Sys_refcursor to dynamic record type

Hi there,
I had a procedure A that is calling procedure B to return the sys_refcursor. And procedure A will using the data that return from cursor procedure B for some processing. Is there anyway that i don't need to fix the record column by calling <record name> <cursor name>%RowType? Because I had an error if i declare the record with the cursor type that not yet open. Example of the code as below.
Procedure ProcA(a1 Integer default Null) Is
cursor1 sys_refcursor;
record1 cursor1%RowType;
Begin
ProcB(0, cursor1);
If cursor1%Isopen Then
Loop
Fetch cursor1
Into record1;
Exit When cursor1%NotFound;
End Loop;
Close cursor1;
End If;
End;
Thanks in advance.

Yes, two methods comes to mind.
The complex, and more "correct", method is to create a DBMS_SQL cursor instead. Such a cursor has a describe interface that allows the receiver to dynamically determine the cursor's number of columns, data types of the the columns and so on.
DBMS_SQL is documented in the Oracle® Database PL/SQL Packages and Types Reference guide.
The second method is easier and flexible, but a bit of a hack as it can only deal with data types that can be implicitly converted to varchar2. It also requires the SELECT statement to call a type constructor using columns as properties for the constructor. The following code illustrates this concept.
SQL> create or replace type TStrings is table of varchar2(4000);
2 /
Type created.
SQL>
SQL>
SQL> create or replace procedure Cursor1( c IN OUT sys_refcursor ) is
2 begin
3 open c for
4 select TStrings( object_id, object_name, object_type ) from all_objects;
5 end;
6 /
Procedure created.
SQL>
SQL>
SQL> create or replace procedure Cursor2( c IN OUT sys_refcursor ) is
2 begin
3 open c for
4 select TStrings( rownum, username ) from all_users;
5 end;
6 /
Procedure created.
SQL>
SQL>
SQL>
SQL> declare
2 c sys_refcursor;
3 cols TStrings;
4
5 procedure W( cLine varchar2 ) is
6 begin
7 DBMS_OUTPUT.put_line( cLine );
8 exception when OTHERS then
9 NULL;
10 end;
11
12 procedure DisplayColumns( s TStrings ) is
13 begin
14 for i in 1..s.Count
15 loop
16 W( 'column '||i||' ['||s(i)||']' );
17 end loop;
18 end;
19
20 begin
21 W( '************' );
22
23 W( 'opening cursor 1' );
24 Cursor1( c );
25 -- fetch only 1 row to demonstrate
26 fetch c into cols;
27 W( 'cursor has '||cols.Count||' columns' );
28 DisplayColumns( cols );
29 close c;
30
31 W( '************' );
32
33 W( 'opening cursor 2' );
34 Cursor2( c );
35 fetch c into cols;
36 W( 'cursor has '||cols.Count||' columns' );
37 DisplayColumns( cols );
38 close c;
39
40 W( '************' );
41 end;
42 /
opening cursor 1
cursor has 3 columns
column 1 [258]
column 2 [DUAL]
column 3 [TABLE]
opening cursor 2
cursor has 2 columns
column 1 [1]
column 2 [RMAN]
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • Executing dynamic procedure with record type

    Hi,
    I have a small issue...I'm not attaching any tables / data..etc...I just want to know how to pass the record type to a procedure (which are actually obtained from a table) dynaically..Unable to form the sql statement..
    I get an error saying that "wrong number or types of arguments in call to ||"...
    -- see ** below where I'm getting an error.
    .Need to pass the whole record type "l_shl_order_msg"
    CREATE OR REPLACE PROCEDURE CM_BUILD_MSG_PRC (P_IN_BLD_MSG_CURSOR IN SYS_REFCURSOR,
                                                  P_OUT_BLD_MSG_CURSOR OUT SYS_REFCURSOR)
    IS
    l_shl_order_msg CRAE_INTERFACE.GLB_VAR_PKG.deid_SHELL_order_typ;
    V_MSG_SHELL_NAME VARCHAR2(1000);
    V_MESG_TEXT_SEGMENT VARCHAR2(1000);
    V_TEXT VARCHAR2(1000);
    V_MSG_TEXT VARCHAR2(4000);
    V_MSG_FINAL_TEXT VARCHAR2(4000);
    V_MSG_PROC VARCHAR2(1000);
    V_SQL VARCHAR2(4000);
    V_CNT NUMBER;
    L_STATUS  VARCHAR2(100);
    L_REASON  VARCHAR2(1000);
    BEGIN
    LOOP
          FETCH P_IN_BLD_MSG_CURSOR
            INTO l_shl_order_msg;
          EXIT WHEN P_IN_BLD_MSG_CURSOR%NOTFOUND;
    END LOOP;
    Select mesg_shell_text, mesg_dynamic_var_count
      into V_MSG_TEXT, V_CNT
       from CRAE_MESG_MASTER
        where mesg_shell_name = l_shl_order_msg.SHELL_ID;
      For i in 1..V_CNT
        LOOP
            SELECT MESG_SHELL_NAME, MESG_TEXT_SEGMENT, PROCEDURE_NAME
             INTO V_MSG_SHELL_NAME, V_MESG_TEXT_SEGMENT, V_MSG_PROC
              FROM CRAE_MESG_MASTER_DETAIL
                WHERE I = MESG_SEQ_NUMBER
                 AND  mesg_shell_name = l_shl_order_msg.SHELL_ID;
      V_SQL:= 'BEGIN '||V_MSG_PROC||'(''' || l_shl_order_msg|| ''',' ||
         '''' || V_MSG_SHELL_NAME || ''',' || '''' || V_MESG_TEXT_SEGMENT
         || ''', CRAE_INTERFACE.GLB_VAR_PKG.V_TEXT );'||'END;';
        DBMS_OUTPUT.PUT_LINE(V_SQL);
         EXECUTE IMMEDIATE (V_SQL);
         V_TEXT := CRAE_INTERFACE.GLB_VAR_PKG.V_TEXT;
         IF I = 1
           THEN
         V_MSG_TEXT := REPLACE(V_MSG_TEXT,V_MESG_TEXT_SEGMENT,V_TEXT);
         V_MSG_FINAL_TEXT := V_MSG_TEXT;
         ELSE
           V_MSG_FINAL_TEXT := REPLACE(V_MSG_FINAL_TEXT,V_MESG_TEXT_SEGMENT,V_TEXT);
         END IF;
    END LOOP;
       DBMS_OUTPUT.PUT_LINE(V_MSG_FINAL_TEXT);
    -- L_STATUS := CRAE_INTERFACE.GLB_VAR_PKG.V_STATUS;
    -- L_REASON := CRAE_INTERFACE.GLB_VAR_PKG.V_REASON;
    OPEN  P_OUT_BLD_MSG_CURSOR
    FOR
        SELECT  l_shl_order_msg.MESSAGE_DATE_TIME,
                 l_shl_order_msg.MASKED_ID,
                 l_shl_order_msg.OFFSET_DATE,
                 l_shl_order_msg.PATIENT_ACCOUNT_NUMBER,
                 l_shl_order_msg.ORDER_CONTROL,
                 l_shl_order_msg.PLACER_ORDER_NUMBER,
                 l_shl_order_msg.QUANTITY,
                 l_shl_order_msg.INTERVAL,
                 l_shl_order_msg.DURATION,
                 l_shl_order_msg.START_DATE_TIME,
                 l_shl_order_msg.END_DATE_TIME,
                 l_shl_order_msg.PRIORITY,
                 l_shl_order_msg.ORDERING_DATE,
                 l_shl_order_msg.ENTERED_BY_ID,
                 l_shl_order_msg.ENTERED_BY_FAMILY_NAME,
                 l_shl_order_msg.ENTERED_BY_GIVEN_NAME,
                 l_shl_order_msg.ORDERED_BY_ID,
                 l_shl_order_msg.ORDERED_BY_FAMILY_NAME,
                 l_shl_order_msg.ORDERED_BY_GIVEN_NAME,
                 l_shl_order_msg.REPEAT_PATTERN,
                 l_shl_order_msg.DRUG_CODE,
                 l_shl_order_msg.DRUG_DESCRIPTION,
                 l_shl_order_msg.REQUESTED_GIVE_AMOUNT,
                 l_shl_order_msg.REQUESTED_GIVEN_UNIT,
                 l_shl_order_msg.SIG,
                 l_shl_order_msg.ALLOW_SUBSTITUTION,
                 l_shl_order_msg.REQUESTED_DISPENSE_AMOUNT,
                 l_shl_order_msg.REQUESTED_DISPENSE_UNIT,
                 l_shl_order_msg.REFILLS,
                 l_shl_order_msg.ROUTE,
                 l_shl_order_msg.STATUS,
                 l_shl_order_msg.REASON,
                 V_MSG_FINAL_TEXT,
                 T.COMP_ID,
                 T.PROC_ID,
                 T.Procedure_Desc
              FROM CRAE_MESG_rule_MASTER T
               WHERE MSG_SHELL_NAME = l_shl_order_msg.SHELL_ID;
    --  dbms_output.put_line (l_shl_order_msg.MESSAGE_DATE_TIME);
    END;** I get an error saying that "wrong number or types of arguments in call to ||"...
    Not sure how to pass record type dynamically...

    sb,
    declare
        l_shl_order_msg CRAE_INTERFACE.GLB_VAR_PKG.deid_SHELL_order_typ;
        V_MSG_SHELL_NAME VARCHAR2(1000);
        V_MESG_TEXT_SEGMENT VARCHAR2(1000);
        V_SQL VARCHAR2(4000);
        V_MSG_PROC VARCHAR2(1000);
        begin
        V_SQL := 'BEGIN '||V_MSG_PROC||'(l_shl_order_msg)'||'END;';
           DBMS_OUTPUT.PUT_LINE(V_SQL);
          end;when I execute this...l_shl_order_msg is passed as variable..but instead I want to pass all columns in the recordtype to be passed..
    ex : l_shl_order_msg.id, l_shl_order_msg.name....etc..
    This is what is being passed :
    BEGIN ATTRIBUTE_PRC( l_shl_order_msg ,'CDS_1','text-1', CRAE_INTERFACE.GLB_VAR_PKG..V_TEXT );
    ATTRIBUTE_PRC has already been defines as record type with i/p parameter..
    Edited by: user7431648 on Jul 26, 2012 8:25 AM
    Edited by: user7431648 on Jul 26, 2012 8:27 AM

  • Pass a record type vaiable in out parameter of a function in a package

    Hi All,
    1.I have created a ecod inside a package.
    2.Then created a function which has a out parameter of the above record.
    3.Now package body i'm creating a dynamic cursor .
    4.My equirement is to fetch this dynamic cursor's value into the out parameter of the function.
    I have created the below code for 1,2 and 3 but not getting how to achive the point 4.
    create package pkg
    type t_rec is recod (id number,id_name varchar2(10));
    type t_data is table of t_rec index by binary_integer;
    act_data t_data;
    funcion return_data is (dept in number,region in number,o_rec out t_data) return boolean;
    end pkg;
    create package body pkg
    funcion return_data is (dept in number,region in number,o_rec out t_data) return boolean is
    p_cur sys_refcursor;
    l_text varchar2(100);
    begin
    -- As per my requirement i have built a dynamic l_text which contains where clause by taking dept and region values.In actual i have nearly 10 in paramaters with >which i'm building a dynamic where clause in l_text. So i'm using a ref cursor.
    open p_cur for 'select id,id_name from tab1'||l_text';
    fetch p_cur bulk collect into act_data;
    exception ....
    end pkg;Now as per the code snippet i could fetch all the rows returned by p_cur into act_data.
    But how i will pass it though out parameter in the function which i will use somewhere in front end to show data.
    Please help me in this.
    Thanks in advance.

    bp wrote:
    i need to create the where clause one the basis of the values of IN parameters.Sometimes i need to take count of the data on the basis of the IN parameters and if one of the conditions return value i will build where clause with those parameters.Please google and read up on the importance of creating shareable SQL - which needs to be done using bind variables.
    The ref cursor interface in PL/SQL only support a static/fixed number of bind variables. So if you want to create cursors with variable number of bind values, you need to use conditional processing. E.g.
    SQL> create or replace procedure EmpFilter( c OUT sys_refcursor, nameFilter varchar2, jobFilter varchar2 ) is
      2          sqlSelect       varchar2(32767);
      3  begin
      4          --// we pretend to built a dynamic SQL statement - so the table
      5          --// name and so on is "unknown"
      6          sqlSelect := 'select * from emp ';
      7          case
      8                  when nameFilter is null and jobFilter is null then
      9                          open c for sqlSelect;
    10
    11                  when nameFilter is null and jobFilter is not null then
    12                          sqlSelect := sqlSelect||'where job like :filter';
    13                          open c for sqlSelect  using jobFilter;
    14
    15                  when nameFilter is not null and jobFilter is null then
    16                          sqlSelect  := sqlSelect||'where ename like :filter';
    17                          open c for sqlSelect  using nameFilter;
    18
    19                  when  nameFilter is not null and jobFilter is not null then
    20                          sqlSelect  := sqlSelect||'where ename like :filter1 and job like :filter2';
    21                          open c for sqlSelect  using nameFilter, jobFilter;
    22
    23          end case;
    24
    25          DBMS_OUTPUT.put_line( 'Dynamic SQL: '||sqlSelect );
    26  end;
    27  /
    Procedure created.
    SQL>
    SQL>
    SQL> var c refcursor
    SQL> begin
      2          EmpFilter( :c, 'A%', null );
      3  end;
      4  /
    Dynamic SQL: select * from emp where ename like :filter
    PL/SQL procedure successfully completed.
    SQL> print c
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7499 ALLEN      SALESMAN        7698 1981/02/20 00:00:00       1600        300         30
          7876 ADAMS      CLERK           7788 1987/05/23 00:00:00       1100                    20
    SQL>
    SQL> begin
      2          EmpFilter( :c, null, 'ANALYST' );
      3  end;
      4  /
    Dynamic SQL: select * from emp where job like :filter
    PL/SQL procedure successfully completed.
    SQL> print c
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7788 SCOTT      ANALYST         7566 1987/04/19 00:00:00       3000                    20
          7902 FORD       ANALYST         7566 1981/12/03 00:00:00       3000                    20
    SQL>And this approach is for external clients - where a Visual Basic or Java client program calls the database, executes the stored procedure, and receives a cursor handle in turn. And the client then fetches the output of this cursor and process it.
    There is no need to return a record type of any sorts. The client wants the cursor handle as that is the optimal and best interface for the client to receive database data.
    If the caller is not an external client, but another PL/SQL procedure, then this approach does not make much sense.
    It is important that you understand basic Oracle concepts and fundamentals. What a cursor is. What the best way is to process Oracle data. How to best use the basic features of Oracle. Without that basic understanding, you as good as a low hour Cessna pilot getting into an Airbus A400M - where the Cessna pilot would not even be able to start a single engine, never mind get the plane in the air.
    Likewise, without a basic understanding of Oracle cursors and fundamentals, you will be unable to code even a single line of sensible code. Not because you are a bad programmer. Even the best programmer in the world will be unable to write decent code, if the programmer has no idea how the environment works, what the concepts and fundamentals are. But it is fair to expect that a good programmer will no write such code, understand that there is a lack of knowledge, and address that accordingly.

  • Regular expression help to solve sys_refcursor for a record

    In reference to my thread Question on sys_refcursor with record type , I thought it can be solved differently. That is:
    I have a string like '8:1706,1194,1817~1:1217,1613,1215,1250'
    I need to do some manipulation using regular expressions and acheive some thing like
    select * from <table> where
    c1 in (8,1)
    and c2 in (1706,1194,1817,1217,1613,1215,1250);Is it possible using regular expressions in a single select statement?

    Hi,
    Clearance 6`- 8`` wrote:
    Your understanding is absolutely correct. But unfortunately it did not work Frank.
    SQL> SELECT COUNT (*)
    2    FROM (SELECT sp.*
    3            FROM spml sp, spml_assignment spag
    4           WHERE sp.spml_id = spag.spml_id
    5             AND spag.class_of_svc_id = 8
    6             AND spag.service_type_id IN (1706, 1194, 1817)
    7             AND spag.carrier_id = 4445
    8             AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    9             AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    10             AND spag.unit_id = 5
    11             AND sales_org_id = 1
    12          UNION ALL
    13          SELECT sp.*
    14            FROM spml sp, spml_assignment spag
    15           WHERE sp.spml_id = spag.spml_id
    16             AND spag.class_of_svc_id = 1
    17             AND spag.service_type_id IN (1217, 1613, 1215, 1250)
    18             AND spag.carrier_id = 4445
    19             AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    20             AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    21             AND spag.unit_id = 5
    22             AND sales_org_id = 1);
    COUNT(*)
    88
    SQL> SELECT COUNT (*)
    2    FROM spml sp, spml_assignment spag
    3   WHERE sp.spml_id = spag.spml_id
    4     AND spag.carrier_id = 4445
    5     AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    6     AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    7     AND spag.unit_id = 5
    8     AND sales_org_id = 1
    9     AND REGEXP_LIKE ('8:1706,1194,1817~1:1217,1613,1215,1250',
    10                      '(^|~)' || spag.class_of_svc_id || ':'
    11                     )
    12     AND REGEXP_LIKE ('8:1706,1194,1817~1:1217,1613,1215,1250',
    13                      '(:|,)' || spag.service_type_id || '(,|$)'
    14                     );
    COUNT(*)
    140
    SQL> Edited by: Clearance 6`- 8`` on Aug 11, 2009 8:04 PMJust serving what you ordered!
    Originally, you said you were looking for something that produced the same result as
    where   c1 in (8, 1)
    and      c2 in (1706, 1194, 1817, 1217, 1613, 1215, 1250)that is, any of the c1s could be paired with any of the c2s.
    Now it looks like what you want is
    where     (     c1 = 8
         and     c2 IN (1706, 1194, 1817)
    or     (     c1 = 1
         and     c2 IN (1217, 1613, 1215, 1250)
         )that is, c1=8 and c2=1250 is no good; neither is c1=1 and c2=1706.
    In that case, try
    WHERE     REGEXP_LIKE ( s
                  , '(^|~)' || c1
                         || ':([0-9]+,)*'
                         || c2
                         || '(,|~|$)'
                  )

  • Workflow for record type = User

    Hi All,
    I would like to create an WF for record type = 'User' that will update one 'User' object field based on the value entered in other 'User' object field.
    Simple to do for any record type except 'User' which is not an option in the Workflow Rule New record type LOV, any ideas for an workaround here?
    10x,
    AlexD.

    Hi Alex, unfortunately I have no answer, but I´m looking for something similar. I want to link object fields of the user´s direct manager to the appropriate object fields of the user. I don´t wanna save the values via a workflow, as the value should be dynamic if it changes in the user profile of the manager.
    If this could be combined with a dynamic user layout for the administrator it would enable perfect user management. Does anyone have an idea? Many thanks, Joerg

  • Return rows from pl-sql record type

    We have a requirement to create function which returns cursor to java application. This cursor will have data from pl-sql record type.
    Tried with pipelined function. I have written code below.
    CREATE or replace PACKAGE test_pkg IS
        TYPE tp_rec IS RECORD(tt_id INTEGER,tt_text VARCHAR2(40));
        TYPE obj_tp_recs IS TABLE OF tp_rec;
        TYPE obj_tp_recs1 IS TABLE OF tp_rec;
        FUNCTION test_func RETURN tp_rec;
        function type_out return obj_tp_recs1 PIPELINED;
        PROCEDURE test_type (result out sys_refcursor);
    END;
    CREATE OR REPLACE PACKAGE BODY OMS.test_pkg IS
        FUNCTION test_func RETURN tp_rec
        AS
           currec tp_rec;
        BEGIN
           currec.tt_id := 1;
           currec.tt_text := 'test1';
        END;
         FUNCTION type_out RETURN obj_tp_recs1 PIPELINED
             AS
           currec1 test_pkg.tp_rec;
          begin
                    currec1 := test_pkg.test_func;
                    PIPE ROW(currec1);
                    dbms_output.put_line(currec1.tt_id);
                end;
        PROCEDURE test_type (result out sys_refcursor)
        AS   
        BEGIN
                  OPEN RESULT
                  FOR SELECT * FROM TABLE(test_pkg.type_out());
        END;
    END;
    SQL> VARIABLE x REFCURSOR
    SQL> exec test_pkg.test_type(:x);
    PL/SQL procedure successfully completed.
    SQL> print xThis code returns no data found exeception from function. How to achieve result 1 and test1 from above code?
    Thanks in advance

    SQL> VARIABLE x REFCURSOR
    SQL> exec test_pkg.test_type(:x);
    PL/SQL procedure successfully completed.
    SQL> print x
    ERROR:
    ORA-06503: PL/SQL: Function returned without value
    ORA-06512: at "SCOTT.TEST_PKG", line 8
    ORA-06512: at "SCOTT.TEST_PKG", line 14
    no rows selectedIf you look at test_func body it is missing return statement. Now:
    SQL> CREATE OR REPLACE PACKAGE BODY test_pkg IS
      2      FUNCTION test_func RETURN tp_rec
      3      AS
      4         currec tp_rec;
      5      BEGIN
      6         currec.tt_id := 1;
      7         currec.tt_text := 'test1';
      8         RETURN currec;
      9      END;
    10     
    11       FUNCTION type_out RETURN obj_tp_recs1 PIPELINED
    12       AS
    13         currec1 test_pkg.tp_rec;
    14        begin
    15          currec1 := test_pkg.test_func;
    16          PIPE ROW(currec1);
    17          dbms_output.put_line(currec1.tt_id);
    18          end;
    19  
    20      PROCEDURE test_type (result out sys_refcursor)
    21      AS   
    22      BEGIN
    23        OPEN RESULT
    24        FOR SELECT * FROM TABLE(test_pkg.type_out());
    25       
    26      END;
    27  END;
    28  /
    Package body created.
    SQL> exec test_pkg.test_type(:x);
    PL/SQL procedure successfully completed.
    SQL> print x
         TT_ID TT_TEXT
             1 test1
    SQL> SY.

  • Auto-populating fields based on another field (must access dif record type)

    This is a long one. I basically want to know if it's possible to have several fields auto-populated based on the data in another. It gets a little tricky here, because the information I want to auto-populate will have to be searched for in another record type. An example will hopefully make my request clear:
    I have 10's of thousands of records of the "Product" record type that each have a product number. Well, let's say I have several fields to enter into an "Opportunity" record type, based on the information for this product number in the "Products" record type. I want to know if I can enter the product number on the "Opportunity" record, and have OnDemand go look up this product number in the "Product" record type, pull information from that record, and auto-populate that additional information in certain fields back on the "Opportunity" record that I am entering information for.
    I know a workflow can do this on simple things where you have a few different part numbers and can create a workflow for each, but I literally have 40k part numbers, and I can't very well create that many workflows. If there was a way to dynamically script the workflow to use the part number in the field on the "Opportunity" record and go fetch the data to auto-populate, that would be nice.
    I also can't use a cascading picklist because, again, there are around 40k products records and picklists have a limit to how many choices you can have.
    My think tank has run empty, and I am out of ideas. I was wondering if there is any other way to get this done, or if it's even possible?
    Thanks,
    B
    Edited by: user10885599 on Feb 5, 2009 11:54 AM

    As I read this, I am wondering if you would be able to use the new JoinFieldValue() function to update the fields. The problem is that the Opportunity record does not have a direct link to products. The Revenue table does however, so you should be able to do this from Revenue, if that is how you are using the application.
    The process would be to create a workflow that watches for new Revenue records, and updates the new fields in the Revenue object using the JoinFieldValue function to pull the data.

  • Error while creating function with record type as return type

    Hi i tried the following code to get the nth highest sal using record type and function.
    CREATE OR REPLACE PACKAGE pack_rec_cur AS
    TYPE rec_type IS RECORD (
    name EMP.ename%TYPE,
    sal EMP.sal%TYPE);
      END;The above package is created
    CREATE OR REPLACE
      FUNCTION fun_rec_cur(n INT) RETURN pack_rec_cur.rec_type AS
       rec pack_rec_cur.rec_type;
        CURSOR cur_rec IS
          SELECT ename,sal
            FROM emp
             WHERE sal is not null
              ORDER BY DESC;
    BEGIN
    OPEN cur_rec;
      FOR i IN 1..n LOOP
       FETCH cur_rec into rec;
       EXIT WHEN cur_rec%NOTFOUND;
      END LOOP;
    CLOSE cur_rec;
    RETURN rec;
    END;   The above function is giving errors
    LINE/COL ERROR
    4/7      PL/SQL: SQL Statement ignored
    7/16     PL/SQL: ORA-00936: missing expression
    SQL> Could you please correct me where i'm doing mistake
    Thanks.

    You are missing the column name in order by clauase. Is it ename desc?
    CREATE OR REPLACE
      FUNCTION fun_rec_cur(n INT) RETURN pack_rec_cur.rec_type AS
       rec pack_rec_cur.rec_type;
        CURSOR cur_rec IS
          SELECT ename,sal
            FROM emp
             WHERE sal is not null
              ORDER BY ENAME DESC; ---added ename
    BEGIN
    OPEN cur_rec;
      FOR i IN 1..n LOOP
       FETCH cur_rec into rec;
       EXIT WHEN cur_rec%NOTFOUND;
      END LOOP;
    CLOSE cur_rec;
    RETURN rec;
    END;  
    -OUTPUT
    SQL> SET SERVEROUT ON
    SQL>
    SQL> DECLARE
      2     rec            pack_rec_cur.rec_type;
      3  BEGIN
      4     rec         := fun_rec_cur (6); --you get the 6th record in order of ename desc
      5     DBMS_OUTPUT.put_line ('ename::' || rec.NAME || '  sal ::' || rec.sal);
      6  END;
      7  /
    ename::MARTIN  sal ::1250
    PL/SQL procedure successfully completed.
    SQL>

  • Error in using plsql record type inside packages

    Dear Friends,
    Using Ora9iR2 on Windows 2000 Server. I am trying to declare a record type and a nested table of that record type in the package body and the initialise that in the package body then insert records into that. But I receive error msg.
    CREATE OR REPLACE PACKAGE sample1 AS
    TYPE rcur IS REF CURSOR;
    TYPE emp_record IS RECORD
    (empname VARCHAR2(20),
    job VARCHAR2(10),
    salary NUMBER);
    TYPE emp_result IS TABLE OF emp_record;
    PROCEDURE emp_test ( i_empno emp.empno%TYPE);
    END sample1;
    -- Package Body
    CREATE OR REPLACE PACKAGE BODY sample1 AS
    PROCEDURE emp_test ( i_empno IN emp.empno%TYPE)AS
    c1 rcur;
    eresult emp_result := emp_result();
    v_empname VARCHAR2(20);
    v_job VARCHAR2(10);
    v_sal NUMBER;
    BEGIN
    OPEN c1 FOR SELECT ename,job,sal FROM emp WHERE empno = i_empno;
    LOOP FETCH c1 INTO v_empname,v_job,v_sal;
    EXIT WHEN c1%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_empname||' , '||v_job||' , '||v_sal);
    eresult := emp_result(v_empname,v_job,v_sal); showing error
    END LOOP;
    CLOSE c1;
    END emp_test;
    END sample1;
    While executing the procedure with out the line eresult := emp_result(v_empname,v_job,v_sal); the procedure executes fine.
    SQL> execute sample1.emp_test(7900);
    JAMES , CLERK , 950
    PL/SQL procedure successfully completed.
    With that line, i have error
    SQL> execute sample1.emp_test(7900);
    BEGIN sample1.emp_test(7900); END;
    ERROR at line 1:
    ORA-04068: existing state of packages has been discarded
    ORA-04063: package body "KUMAR.SAMPLE1" has errors
    ORA-06508: PL/SQL: could not find program unit being called
    ORA-06512: at line 1
    While executing in PL/SQL Developer, it says the wrong number or types of arguments call to ;EMP_RESULT'.
    Please guide me where I am wrong.
    Kumar

    I got invalide data type error.I think the datatype in the CAST() clause must be a SQL Type i.e. one created with a CREATE TYPE command in the database. emp_result is only a PL/SQL datatype.
    But I dont know why it is saying error
    eresult(eresult.count) := emp_result(v_empname,v_job,v_sal); eresult is a table of records. It is therefore expecting a record. records don't seem to be created in the same way that user defined types are.
    The concept of handling records like this is new to 9i and they are still smoothing out the bumps. Things are a lot better in 9.2 than in 9.0.1 if it's any consolation. There is a particular gap in the documentation, which is what's tripping you up at the moment: the difference between TYPE AS RECORD and other types, also the difference between VARRAY, NESTED TABLE and REF CURSOR. To be honest, it's all kind of hazy for me at the moment: I always need to run some code before I make any pronouncements on this topic.
    Good luck, APC

  • How create a record type and a pl/sql table of that record type in database

    Hi
    I want to create a record type and then I want to create a PL/SQL table in the oracle 9i database.
    I have done it in PL/SQL block.
    But when I am trying to do it in database it is throwing me some error.
    Could you please tell me how can I do that?
    Regards

    user576726 wrote:
    Hi
    I want to create a record type and then I want to create a PL/SQL table in the oracle 9i database.
    I have done it in PL/SQL block.
    But when I am trying to do it in database it is throwing me some error.
    Could you please tell me how can I do that?
    RegardsRECORD type is supported only in PL/SQL for SQL you need to use OBJECT type.

  • How to assigne value in sub record type

    Dear below mention record type database,now i want to assigne value in payr_rec type,in this recrocrd type have one column party_id,but how can assigne value int this field ,
    TYPE group_rec_type IS RECORD(
    group_name VARCHAR2(255),
    group_type VARCHAR2(30),
    created_by_module VARCHAR2(150),
    -- Bug 2467872
    mission_statement VARCHAR2(2000),
    application_id NUMBER,
    party_rec PARTY_REC_TYPE := G_MISS_PARTY_REC
    please guide.

    to get the desired default party_rec attribute value, just assign the "sub-record" attribute defaults as desired; PL/SQL will assign a default (non-null) record as the party_rec value using those attribute defaults:
    create or replace package P_Test_It
    as
         type party_rec_type is record (
              dummy varchar2(1) default 'X'
         type group_rec_type is record (
              group_name VARCHAR2(255),
              group_type VARCHAR2(30),
              created_by_module VARCHAR2(150),
              -- Bug 2467872
              mission_statement VARCHAR2(2000),
              application_id NUMBER,
              party_rec PARTY_REC_TYPE
    end;
    set serveroutput on
    declare
         rec p_test_it.group_rec_type;
    begin
         dbms_output.put_line(rec.party_rec.dummy);
    end;
    X
    PL/SQL procedure successfully completed.Hope it helps.
    Gerard

  • How do you save dynamic data type, from the DAQ assistant, for use in Excel or matlab?

    Currently, I have the following basic VI setup to save Data from my PCI6221 Data Aquisition Card.  The problem I'm having is I keep getting the last iteration of the while loop in the measurement file and that's pretty much it.  When I try to index the data leaving the loop it gives me a 2D array of Data which cannot be input into the "Write to Measurement File" VI.  How would I save this to a useful Data/time step format?  I was wondering of a way to continuously collect the Data and then save it in a large measurement file that I would manipulate in Matlab/excel?  Am I using the wrong type of loop for this application?  I also noticed my Dynamic Data array consists of data, time, timestep and then a vector of the data taken.  Is it possible to just get a vector of the time change per sample alongside the data?    Sorry for the barrage of questions but any help would be greatly appreciated, and thanks in advance!
    -Bryan
    Attachments:
    basic DAQ.vi ‏120 KB

    There is a VI in the Express > Signal Manipulation palette called "From DDT" that lets you convert from the Dynamic Data Type to other data types that are more compatible with operations like File I/O....for instance, you could convert your DDT into a 2D array and use the Write To Spreadsheet File.vi.  Just a thought...
    -D
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • ACH CTX - Addenda Record Type 7

    Hi,
    I am working on ACH CTX file for vendor payments through Wells Fargo bank. I need some help on the Addenda Record type 7. The format generated by standard SAP for this record type 7 is not acceptable by the bank. And they are not able to help us out much on what should be the format. All they say is that it should be in ANSI ASC X12 format (payment-related information) and refer NACHA format guidelines. Can anyone tell me what is this NACHA format and what data elements should be passed on in this record type. Is there a specific format I can follow?
    Thanks,
    Raj/

    Hi,
    did you solve this items. Any information would be helpful.
    thanks
    Regards
    PG

  • Howto post offsetting entries for Record type Z Line items in KE24 from FI

    HI,
    We are facing one problem for order created from CRM.
    Firstly this order  has created  with one profit center ( ex PH50293 ) they have posted some plan values and released the order in CRM so values flown to ECC and available in KE24 .
    After some time , we have changed profit center for this order in CRM by changing  service organisation and release the order after that we have posted some values in that order which is not flown to ECC becuase of different profit center
    Later we rejected the all values and make balance zero in CRM , But still values are appearing in KE24 and there is inconsistency of profit center between ECC & CRM.
    Now want to make the balances zero in KE24 for that order. but it shows record type Z ,
    So , now how we can rectify this and how we can make balances zero
    __Note :  as per present setting in the system, we can not change the profit center in CRM once order released_._
    Thanks & Regards
    Gupta

    Dear VK,
    I guess, the only option would be to post manual correction thru KE21N, with negative values for record type Z.
    Trust this helps.
    Cheers.

  • Oracle Account Receivables Lockbox Error, No ITEM NUM on PAYMENT record type.

    Hi,
    For "Process Lockbox" program. The program completes normally, but receipts are not created and I am getting below error in log file:-  
    "AR-ARLFMT: No ITEM NUM on PAYMENT record type."
    This error message is similar to error message mentioned in note id (Troubleshooting Known Issues In Lockbox (Doc ID 1366298.1)) :-
    2.10. Lockbox ends with error: "AR-ARLFMT: No PAYMENT NUM on PAYMENT record type"
    Symptoms
    You are trying to run lockbox and receive this error message in the log file:
    AR-ARLFMT: No PAYMENT NUM on PAYMENT record type.
    Your lockbox interface program has completed successfully, however,there is No Data Found in the AR_PAYMENTS_INTERFACE table.
    Solution
    Responsibility: Receivables Manager
    Navigation: Setup > Receipts > Lockboxes > Transmission Formats
    For the Transmission Format name that you are using, make sure that there is a 'Transmission Record' defined and that there is a Transmission Field with a Field Type of  'Record Identifier' defined.
      Make sure to include the check number in Transmission Format and Control file
    and item number is:-
    Item Number: A sequence number that your bank assigns to a specific payment. This number associates an invoice with a receipt.
    I am passing item number, but still I am getting this error.
    Can anybody please help.
    Thanks in advance.
    Regards
    Gagan Garg

    Hi,
    For "Process Lockbox" program. The program completes normally, but receipts are not created and I am getting below error in log file:-  
    "AR-ARLFMT: No ITEM NUM on PAYMENT record type."
    This error message is similar to error message mentioned in note id (Troubleshooting Known Issues In Lockbox (Doc ID 1366298.1)) :-
    2.10. Lockbox ends with error: "AR-ARLFMT: No PAYMENT NUM on PAYMENT record type"
    Symptoms
    You are trying to run lockbox and receive this error message in the log file:
    AR-ARLFMT: No PAYMENT NUM on PAYMENT record type.
    Your lockbox interface program has completed successfully, however,there is No Data Found in the AR_PAYMENTS_INTERFACE table.
    Solution
    Responsibility: Receivables Manager
    Navigation: Setup > Receipts > Lockboxes > Transmission Formats
    For the Transmission Format name that you are using, make sure that there is a 'Transmission Record' defined and that there is a Transmission Field with a Field Type of  'Record Identifier' defined.
      Make sure to include the check number in Transmission Format and Control file
    and item number is:-
    Item Number: A sequence number that your bank assigns to a specific payment. This number associates an invoice with a receipt.
    I am passing item number, but still I am getting this error.
    Can anybody please help.
    Thanks in advance.
    Regards
    Gagan Garg

Maybe you are looking for

  • My keyboard on macbook pro (laptop) is acting weird. One key is not responding at all. Have verified using Keyboard viewer and some other keys are printing the unresponsive character at random.

    my keyboard on macbook pro (laptop) is acting weird. One key is not responding at all. Have verified using Keyboard viewer and some other keys are printing the unresponsive character at random. "z" is the unresponsive character. Is it a damaged keybo

  • Shuffle 3G Not Working With *New* Headphones

    I won a 3rd Generation Shuffle a few years ago and have only just now decided to actually use it.  I used the original shuffle headhphones for my iPhone at the time (because I run through headphones like an elephant on a stampede) and they are now de

  • IMac "20 CRASH

    Hello, I have a big problem with my new 20" iMac. The computer crashes without any reason. At first I though it was Autodesk Maya's problem, but then I noticed it also crashes in other programs. When it crashes, the watch stops, and I can't do anythi

  • Can a JSP return an image?

              Can a JSP page be written so that it returns an image? What are the           available MIME types that can be returned? IOW, what is the possible values           of the "page" directive attribute "content-type"? Better yet, where can I   

  • Versions in Header tab

    hi all, when i create PO with ME21n , then there is one tab in Header data  called  VERSIONS. that is missing . when i create po with one purchase organization , it is coming. and when create  purchase order with another purchase organizatios, then v