refcursor

Hi Master,

I have a small doubt on slider REF. especially on this point. I search in google for an example. But no luck. Please notify.

"The main advantage of the use of cursor variables is their ability to move from result sets between the subprogrammes (such as stored procedures functions packages etc.)."

How can I take a proc released as another proc entry value? Please give me an example or a nice url on it?

It's very kind of you.

Concerning

AR

Here is an example. GET_EMP how to get the details of the employee for a given DEPTNO and the print PRINT_EMP method details.

SQL> declare
  2    rc sys_refcursor;
  3
  4    procedure get_emp(pdeptno integer, pempdet out sys_refcursor)
  5    is
  6    begin
  7       open pempdet for select empno, ename from emp where deptno = pdeptno;
  8    end;
  9
 10    procedure print_emp(pempdet sys_refcursor)
 11    is
 12      lempno integer;
 13      lename varchar2(100);
 14    begin
 15      loop
 16        fetch pempdet into lempno, lename;
 17        exit when pempdet%notfound;
 18        dbms_output.put_line('EmpNo = ' || to_char(lempno, '09999999999') || ' Ename = ' || lename);
 19      end loop;
 20    end;
 21  begin
 22    get_emp(10, rc);
 23    print_emp(rc);
 24  end;
 25  /
EmpNo =  00000007782 Ename = CLARK
EmpNo =  00000007839 Ename = KING

PL/SQL procedure successfully completed.

SQL>

Tags: Database

Similar Questions

  • Accidental Refcursor

    Hi guys,.

    I stumbled upon this procedure using refcursor inside a loop, as below. My understanding is that the person wrote the code thinking it will add the data in the cursor.

    create or replace PROCEDURE (proc_test)

    RC1 ON SYS_REFCURSOR)

    cursor CSR is separate select deptno from emp;

    Start

    for rec loop of CSR

    Open rc1 for "select * from Department where deptno = ' |" Rec.DEPTNO;

    -make your...

    end loop;

    close the CSR;

    end;

    /

    I have it except to error with cursor already open, instead, I got a few results im not able to correlate.

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    "CORE 11.2.0.3.0 Production."

    AMT for Linux: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    As usual, it helps to RTFM. Opening and closing of cursor Variables:

    You must not close a cursor variable before reopening it (i.e. use it in another OPEN FOR instruction). After having reopened a cursor variable, the previously associated query there is lost.

    SY.

  • Need help with the refcursor parameter

    I need help in writing sql for the script logic

    Procedure p1 (str in varchar2,

    o_refcur on refcursor)

    as

    Start

    Open the o_refcur for

    logic of SQL;

    .....

    end;

    /

    When I contribute to my procedure like this "ABCDEFGY", my procedure must then return the refcursor by separating each letter and she as a Recordset.

    My expected result:

    A

    B

    C

    D

    E

    F

    G

    THERE

    Kindly help...

    create or replace

    Procedure p1 (str in varchar2,

    o_refcur on SYS_REFCURSOR)

    as

    Start

    Open the o_refcur for

    Select the double substr(STR,level,1) connect by level<>

    end;

    /

    SET SERVEROUTPUT SIZE 1000000

    DECLARE

    l_cursor SYS_REFCURSOR;

    STR VARCHAR2 (20): = 'ABCDEFGH ';

    l_ch VARCHAR2 (1);

    BEGIN

    P1 (STR, l_cursor);

    LOOP

    SEEK l_cursor INTO l_ch;

    EXIT WHEN l_cursor % NOTFOUND;

    DBMS_OUTPUT. Put_line (l_ch);

    END LOOP;

    CLOSE L_cursor;

    END;

    /

    A

    B

    C

    D

    E

    F

    G

    H

  • Refcursor bind variables

    Hi all

    I have a variable refcursor, to which I will assign running queries.

    All are defined (union) queries, with 5 or 6 selects the union, each select returns the same variable where clause. Value of the variable will be known at run time.

    For example: (just an example)

    {code}

    Start

    v_sql: = ' select col1, col2

    of the Department

    where dept_no =: 1

    Union

    Select col1, col2

    of eur_dept

    where dept_no =: 1

    Union

    Select col1, col2

    of us_dept

    where dept_no =: 1 ';

    Open the v_ref_cur for v_sql using 20, 20, 20;

    -rest of the logic

    ------------

    -----------------

    end;

    {code}

    Question is how to avoid the bind variable value repeat (in the open statement). Is there a way I can mention value 20 only once when the cursor is opened.

    Thank you!

    DS says:

    Question is how to avoid the bind variable value repeat (in the open statement). Is there a way I can mention value 20 only once when the cursor is opened.

    Yes - can be done using a dynamic anonymous block to create the refcursor (containing the SQL text), as oppose to the creation of the refcursor directly from the SQL text.

    Not an approach I consider myself - unless there is absolutely no better way to address this particular issue.

    SQL > var refcursor c.

    SQL >

    SQL > declare

    News 2 sys_refcursor;

    3. start

    4 immediate execution

    5 ' declare

    6 varchar2 (4000) var1: =: 1;  -/ / simple definition var - used several times

    7. start

    open 8: news for

    9 select * from emp where mgr = var1

    10 the union all the

    11. Select * from emp where empno = var1;

    12 end; »

    13 using 7698-past the variable once

    14 in the news; -getting refcursor as answer

    15

    16: c: = cur;

    end 17;

    18.

    PL/SQL procedure successfully completed.

    SQL >

    SQL > print c

    EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR

    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------

    7499 ALLEN SALESMAN 7698 1981/02/20 00:00:00 1600 300 30

    7521 WARD SALESMAN 7698 1981/02/22 00:00:00 1250 500 30

    7654 MARTIN SALESMAN 7698 1981/09/28 00:00:00 1250 1400 30

    7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30

    7900 JAMES CLERK 7698 1981/12/03 00:00:00 950 30

    7698 BLAKE MANAGER 7839 1981/05/01 00:00:00 2850 30

    6 selected lines.

    SQL >

  • Refcursor in the procedure

    Hi all

    There will be no effect in performance if we declare refcurosr with suspicion NOCOPY parameter in a Stored procedure procedure/package?

    AFAIK variable refcursor who will make reference to the calling environment will hold just pointer not data and so avoid a NOCOPY effect.

    Thank you!!

    DS says:

    One of my senior team members asked me to NOCOPY in all existing procedures where refcursor is returned as a parameter in my output project.

    I told him that this will not add any performance improvement and has no effect.

    I did it, because I was forced to do so.

    Want to just check and take the advice from here in this forum.

    I still have the document (in e-mails and in the procedure itself at the top) all these changes so that the future code-reviewers know EXACTLY why this change has been made and who authorized it. Probably you are asking your "senior" you say the reasons to support the change that they requested; You should document those as well.

    Sounds like your "senior" team member is not so superior after all. You can use this as a topic of discussion in your dev group.

    See the doc of the PL/SQL language.

    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/tuning.htm#i48500

    Calls to PL/SQL Tuning subprogramme with NOCOPY hint

    By default, OUT and IN OUT parameters are passed by value. The values of a IN OUT settings are copied before the delivery of the subprogramme. During the execution of the subprogramme, temporary variables to maintain the output parameter values. If the subprogram exits normally, these values are copied to the actual parameters. If the subprogram exits with an unhandled exception, the original settings are unchanged.

    When the parameters represent structures of large data such as collections, records and instances of object types, this reproduction slows down execution and uses memory. In particular, this overload applies to each call to a method of the object: temporary copies are made of all attributes, so that any changes made by the method are only apply if the method ends normally.

    To avoid this overload, you can specify the NOCOPY trick, which allows the PL/SQL compiler to pass OUT and IN OUT parameters by reference. If the subprogram exits normally, the action is the same as usual. If the subprogramme leaves at the beginning with an exception, the values of OUT and IN OUT parameters (or the attributes of the object) can still change. To use this technique, check that the subroutine handles all exceptions.

    Note the reference to the "large data structures. As you already know a REFCURSOR isn't a large data structure, so will not use NOCOPY.

    The most important side effect is that, as noted in the last paragraph above, the characteristics of the 'exit' are modified if you use NOCOPY.

    Point out that the last clause in your "senior": ENSURE THAT THE subprogram MANAGES all THE EXCEPTIONS.

    Normally (i.e. without using NOCOPY) a REFCURSOR lucifera is a parameter OUT will NOT have a value if the procedure stops with an exception if the caller is unable to use it eventually. Maybe this isn't the case if you use NOCOPY.

    Generally however, the use of NOCOPY would simply be an amendment unnecessary, but harmless.

  • execution of the procedure with refcursor as output parameter

    Hi I have the package following a procedure with parameter as refcursor OUT.
    Here is an example of sample with the same structure with name in the other table, handling exceptions in my dev environment
    CREATE OR REPLACE PACKAGE TEST_PACK
      IS
    Type refCursor  is  REF CURSOR;
    PROCEDURE TEST_PROC (out_data out refCursor);
    END;
    
    
    CREATE OR REPLACE PACKAGE BODY TEST_PACK 
     IS
     Procedure test_proc (
            out_data out refCursor
                ) is
        --
        v_sql varchar2(4000);
       
        --
        begin
    
               v_sql := 'select
                        * from emp';
                       
            DBMS_OUTPUT.PUT_LINE ( 'Select Query is: '||v_sql );
    
            open out_data for v_sql;
    
            Exception
                when others then
                    DBMS_OUTPUT.PUT_LINE ( 'Error '|| SQLCODE ||','||SQLERRM );
    
       END;   
    end ;
    When I try to execute this procedure with the followig block
    DECLARE
       TYPE my_newcursor IS REF CURSOR;
       test_cur   my_newcursor;
      out_text      VARCHAR2 (4000);
    BEGIN
       TEST_PACK.test_proc(TEST_CUR) ;
       LOOP
          FETCH test_cur INTO out_text;    
          EXIT WHEN test_cur%NOTFOUND;
          dbms_output.put_line('Value of refcur is:'||out_text);
       END LOOP;
         CLOSE test_cur;  
    END;
    I get the following error
    ORA-00932: inconsistent datatypes: expected - got -
    ORA-06512: at line 8
    Could you please help me where I am doing wrong

    Thank you

    You must extract your data to an appropriate data type.

    (and note there is no need to declare your own ref cursor type as Oracle provides sys_refcursor at the end)

    for example

    SQL> set serverout on
    SQL>
    SQL> create or replace procedure test_proc(out_data out sys_refcursor) is
      2    v_sql varchar2(4000);
      3  begin
      4    v_sql := 'select * from emp';
      5    DBMS_OUTPUT.PUT_LINE ( 'Select Query is: '||v_sql );
      6    open out_data for v_sql;
      7  end;
      8  /
    
    Procedure created.
    
    SQL>
    SQL> declare
      2    rc     sys_refcursor;
      3    empRec emp%rowtype;
      4  begin
      5    test_proc(rc);
      6    loop
      7      fetch rc into empRec;
      8      exit when rc%notfound;
      9      dbms_output.put_line('Employee: '||empRec.empno||' - '||empRec.ename);
     10    end loop;
     11    close rc;
     12  end;
     13  /
    Select Query is: select * from emp
    Employee: 7369 - SMITH
    Employee: 7499 - ALLEN
    Employee: 7521 - WARD
    Employee: 7566 - JONES
    Employee: 7654 - MARTIN
    Employee: 7698 - BLAKE
    Employee: 7782 - CLARK
    Employee: 7788 - SCOTT
    Employee: 7839 - KING
    Employee: 7844 - TURNER
    Employee: 7876 - ADAMS
    Employee: 7900 - JAMES
    Employee: 7902 - FORD
    Employee: 7934 - MILLER
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    Why do you use a slider ref anyway?

    {: identifier of the thread = 886365}

  • How to run a procedure with refcursor to more

    an entry is User_id = CMSH_USER; p_Ot-num =-9999; p_ppst_flag = 'P' and I want to take the trace by running this procedure, and any1 help me, how to run this procedure below and how to use these 5 on refcursor...
     procedure Pr_get_mny(p_ot_Num      IN NUMBER,
                                     p_User_Id      IN VARCHAR2,
                                     p_Ppst_Flag IN VARCHAR2,
                                     Ref_Cur        OUT Ref_Cursor,
                                     CUR_OPT        OUT Ref_Cursor,
                                     CUR_TAXRATE    OUT Ref_Cursor,
                                     CUR_TAXHOLD    OUT Ref_Cursor,
                                     CUR_PENDGAACNT OUT Ref_Cursor
                                     ) IS

    If the goal is to Test, the best tool is SQL

    var ref_cur refcursor
    var cur_opt refcursor
    var cur_taxrate refcursor
    var cur_taxhold refcursor
    var cur_pendgaacnt refcursor 
    
    exec pr_get_mny(-9999,'CMSH_USER','P',:ref_cur,:cur_opt,:cur_taxrate,:cur_taxhold,:cur_pendgaacnt)
    
    print ref_cur
    print cur_opt
    print cur_taxrate
    print cur_taxhold
    print cur_pendgaacnt
    
  • Disadvantages of using REFCURSORs of JDBC

    Hello

    Normally, I write my SQL inside Java (for example PreparedStatements) statements.

    I am studying on the establishment of the PL/SQL Packages, providing the procedures and methods, I can call Java using CallableStatements. I understand the benefits of having a layer/API on the database side.

    For example: extract some records in a table. (the PL/SQL function getCustomers returns a REFCURSOR)

    -PreparedStatement (select... from... where...)->-> loop ResultSet executeQuery
    -CallableStatement ("start?: = getCustomers();") end; ")-> cast getObject() to ResultSet-> loop ResultSet

    ---

    What are the disadvantages of using the CallableStatement (REFCURSOR)?



    Thank you, best regards, Stephan

    >
    I was thinking about the extraction of the differences of lines (line single OR multiple rows per round trip to the DB).

    If I understand correctly, I can set the size of Fetch on a CallableStatement (Oracle), so to get several lines of the REFCURSOR per round trip ticket to the DB.
    >
    Recovery of data from an Oracle database using cursors: no exceptions.

    The JDBC layer is what includes the "batch processing" feature that you describe and the feature is independent of the source of the cursor. If you use Oracle extensions, so you can take advantage of automated dosing of Oracle.

    Using a REF CURSOR is how preferred and recommended to provide data from the database to an external client.

    1. it minimizes dependencies between the DB and the customer. The function/procedure that provides REF CURSOR is the only dependency.

    2. it maximizes the security of the data. Responsibility to secure data is based only on the side DB through the function/procedure. It is simply not possible for the Client software to access the data not authorized unless the function/procedure he has. The customer has NO access to the data, except by the REF CURSOR.

    3. it maximizes the security of the database. Access to the database itself is easier to control. Customers only need to access an account that has extremely limited privileges: privilege to EXECUTE the function/procedure. Customers should not any table, view, or other privileges to do their job.

    4. it minimizes the probability of error by the customer. It is impossible for the client to access the bad table/view or data. Customers don't need to know how to join tables or even know what are the name of the table or where the data resides.

    5. it minimizes the knowledge and skills that the client developer needs to do their work. The client developer can focus on their two main issues: 1) what data do I need for my application, 2) what do I do with this data.

    6. the risk of 'performance' (or sentence) is if the procedure/function is misspelled or uses wrong written queries to get the data.

    In short use a REF CURSOR allows the developer to DB deal with the best way to provide the data and the developer client side withj records how to consume these data.

    Use of any solution other than a REF CURSOR should be the EXCEPTION rather than the rule.

  • Insert the output of a refcursor procedure into a table

    Hello

    I met a scenario in which I need to put the insert records returned by a procedure using refcursor, at a table.

    I followed the instructions in PL/SQL 101: understanding Refcursor (PL/SQL 101: understanding Ref Cursor am unfortunately still not able to do so.)

    Here is my sample codes. (Copied here as advised by the new Member)
    create or replace PROCEDURE TEST_PROCEDURE1 ( p_cursor OUT SYS_REFCURSOR)
    AS
    BEGIN
    OPEN p_cursor FOR
    SELECT C1,C2
    FROM TEST_USER.test_table4procedure;
    END;
    I check the result using the following statement, which gives results.
    variable rc refcursor;
    exec TEST_USER.TEST_PROCEDURE1 (:rc)
    print rc;
    Now, I want to be able to use the output and insert the data into a table. That's how I came across this thread.

    I created the types and function...
    create or replace type test_user.type_table1 as object(var1 varchar2(50),var2 varchar2(50));
    create or replace type test_user.type_table2 as table of test_user.type_table1;
    
    create or replace function test_user.test_function1 (rc in sys_refcursor )
    return test_user.type_table2 is
    v_emptype test_user.type_table2 := test_user.type_table2(); -- Declare a local table structure and initialize it
    v_cnt number := 0;
    v_rc sys_refcursor;
    v_var1 varchar2(20);
    v_var2 varchar2(20);
    begin
    v_rc := rc;
    loop
    fetch v_rc into v_var1, v_var2;
    exit when v_rc%NOTFOUND;
    v_emptype.extend;
    v_cnt := v_cnt + 1;
    v_emptype(v_cnt) := test_user.type_table1(v_var1, v_var2);
    end loop;
    close v_rc;
    return v_emptype;
    end;
    After that, I want to be able to view the records by using the function... so I used the instructions below...
    variable rc refcursor;
    exec TEST_USER.TEST_PROCEDURE1 (:rc)
    SELECT * FROM TABLE(test_user.test_function1(:rc));   
    However, it fails with the error

    Error from line 3 in order:
    SELECT * FROM TABLE (test_user.test_function1 (:rc))
    Error report:
    SQL error: Missing a setting IN or OUT to index: 1

    Help, please...

    Your code does not work for a simple reason. SYS_REFCURSOR parameters must be in IN OUT mode. Check if the RC is open when he switched mode:

    create or replace type type_table1 as object(var1 varchar2(50),var2 varchar2(50))
    /
    create or replace type type_table2 as table of type_table1
    /
    create or replace PROCEDURE TEST_PROCEDURE1 (p_cursor IN OUT SYS_REFCURSOR)
    AS
    BEGIN
    OPEN p_cursor FOR
    SELECT ENAME,JOB FROM EMP;
    END;
    /
    create or replace function test_function1 (rc in sys_refcursor )
    return type_table2 is
    v_emptype type_table2 := type_table2(); -- Declare a local table structure and initialize it
    v_cnt number := 0;
    v_var1 varchar2(20);
    v_var2 varchar2(20);
    begin
    if rc%isopen
      then
        dbms_output.put_line('rc is open');
      else
        dbms_output.put_line('rc is not open');
     end if;
    loop
    fetch rc into v_var1, v_var2;
    exit when rc%NOTFOUND;
    v_emptype.extend;
    v_cnt := v_cnt + 1;
    v_emptype(v_cnt) := type_table1(v_var1, v_var2);
    end loop;
    close rc;
    return v_emptype;
    end;
    /
    variable rc refcursor
    exec TEST_PROCEDURE1(:rc)
    set serveroutput on
    SELECT * FROM TABLE(test_function1(:rc))
    /
    SELECT * FROM TABLE(test_function1(:rc))
                        *
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at "SCOTT.TEST_FUNCTION1", line 15
    
    rc is not open
    SQL> 
    

    Now IN OUT parameter edit mode:

    set serveroutput off
    create or replace function test_function1 (rc in out sys_refcursor )
    return type_table2 is
    v_emptype type_table2 := type_table2(); -- Declare a local table structure and initialize it
    v_cnt number := 0;
    v_var1 varchar2(20);
    v_var2 varchar2(20);
    begin
    if rc%isopen
      then
        dbms_output.put_line('rc is open');
      else
        dbms_output.put_line('rc is not open');
     end if;
    loop
    fetch rc into v_var1, v_var2;
    exit when rc%NOTFOUND;
    v_emptype.extend;
    v_cnt := v_cnt + 1;
    v_emptype(v_cnt) := type_table1(v_var1, v_var2);
    end loop;
    close rc;
    return v_emptype;
    end;
    /
    variable rc refcursor
    exec TEST_PROCEDURE1(:rc)
    set serveroutput on
    declare
    v_emptype type_table2 := type_table2();
    begin
    v_emptype := test_function1(:rc);
    end;
    /
    rc is open
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    Problem is that you can't call the procedure/function with parameters in/out OUT of SQL.

    SY.

  • refcursor in package

    Hello

    Can I use REFCURSOR in the package.

    If not why?

    Yes...
    see the example.

    CREATE OR REPLACE PACKAGE CURSPKG AS
        TYPE T_CURSOR IS REF CURSOR;
        PROCEDURE OPEN_ONE_CURSOR (N_EMPNO IN NUMBER,
                                   IO_CURSOR IN OUT T_CURSOR);
        PROCEDURE OPEN_TWO_CURSORS (EMPCURSOR OUT T_CURSOR,
                                    DEPTCURSOR OUT T_CURSOR);
    END CURSPKG;
    
    CREATE OR REPLACE PACKAGE BODY CURSPKG AS
        PROCEDURE OPEN_ONE_CURSOR (N_EMPNO IN NUMBER,
                                   IO_CURSOR IN OUT T_CURSOR)
        IS
            V_CURSOR T_CURSOR;
        BEGIN
            IF N_EMPNO <> 0
            THEN
                 OPEN V_CURSOR FOR
                 SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
                      FROM EMP, DEPT
                      WHERE EMP.DEPTNO = DEPT.DEPTNO
                      AND EMP.EMPNO = N_EMPNO;
    
            ELSE
                 OPEN V_CURSOR FOR
                 SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
                      FROM EMP, DEPT
                      WHERE EMP.DEPTNO = DEPT.DEPTNO;
    
            END IF;
            IO_CURSOR := V_CURSOR;
        END OPEN_ONE_CURSOR; 
    
        PROCEDURE OPEN_TWO_CURSORS (EMPCURSOR OUT T_CURSOR,
                                    DEPTCURSOR OUT T_CURSOR)
        IS
            V_CURSOR1 T_CURSOR;
            V_CURSOR2 T_CURSOR;
        BEGIN
            OPEN V_CURSOR1 FOR SELECT * FROM EMP;
            OPEN V_CURSOR2 FOR SELECT * FROM DEPT;
            EMPCURSOR  := V_CURSOR1;
            DEPTCURSOR := V_CURSOR2;
        END OPEN_TWO_CURSORS;
    END CURSPKG;
    

    Mezaber

  • How to use refcursor type returned from the remote database in the local database

    Can anyone say is how they use the refcursor use type returned from remote database in the local database using dblinks.

    See MOS ID 750126.1 doc ORA-24338 when trying to return a Refcursor over a database link.

  • How to display Refcursor

    I have a function that returns a refcursor.
    Now, I have view the output of this function, but only using dbms_output.put_line
    Is this Possible and how.

    Thanks in advance.

    A code example

    CREATE OR REPLACE FUNCTION emp_by_job (p_job VARCHAR2,p_deptno NUMBER,pv_table VARCHAR2)
    RETURN SYS_REFCURSOR
    IS
        emp_refcur      SYS_REFCURSOR;
    BEGIN
        OPEN emp_refcur FOR
        'SELECT empno, ename FROM '||pv_table||'  WHERE job = '||''''||p_job||''''||' and deptno= ' ||p_deptno; --Dynamic String where table name column values are parameters
        RETURN emp_refcur;
    END;
    /
    
    declare
      emp_refcur_local      SYS_REFCURSOR;
      empno NUMBER(4);
      ename VARCHAR2(30);
    Begin
      --Calling the function using parameters
      emp_refcur_local:=emp_by_job('MANAGER',10,'EMP');
      LOOP
      FETCH emp_refcur_local into empno,ename;
        EXIT WHEN  emp_refcur_local%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE('Employee no: '||empno||'/ Employee name: '||ename);
      END LOOP;
    end;
    
  • refcursor or object?

    Working on a stored procedure that is called by the java application.

    I do not know which of the following option is better and in which case:

    1 stored procedure return/accepting a SYS_REFCURSOR parameter
    or
    2. at the level of schema:

    TYPE AS OBJECT emp_attrb_obj (attribute_type_id NUMBER (10),)
    attribute_val VARCHAR2 (50)
    );
    create or replace
    TYPE emp_attrb_type AS THE emp_attrb_obj TABLE;

    and then have a stored procedure accepts or returns a parameter of type emp_attrb_type

    Thank you
    RN

    RN says:
    Working on a stored procedure that is called by the java application.

    I do not know which of the following option is better and in which case:

    1 stored procedure return/accepting a SYS_REFCURSOR parameter
    or
    2. at the level of schema:

    TYPE AS OBJECT emp_attrb_obj (attribute_type_id NUMBER (10),)
    attribute_val VARCHAR2 (50)
    );
    create or replace
    TYPE emp_attrb_type AS THE emp_attrb_obj TABLE;

    and then have a stored procedure accepts or returns a parameter of type emp_attrb_type

    Thank you
    RN

    Well, a java application is unlikely to be able to pass a ref cursor, your procedure will therefore not need to accept a. Other than that, it really depends on how the data that you expect to get past back.

    I have a number of stored procs called by java applications that return a single row in a table. In these cases, I often return an object, since it saves a step for Java guys who can use it more or less directly. Is there is not a limit on the number of rows returned exlplicit, then I would always return a refcursor.

    If the java app must pass a set of values in the stored procedure (for example get this list of employees), then I would have java pass an array of objects (an array of records) to the stored procedure. It keeps me from having to parse a delimited string of values.

    John

  • using refcursor

    What exactly is the use of the Ref Cursor?
    they affect performance?
    Thks

    810345 wrote:
    NOW he will also perform the same function as my refcursor played and I think I can also use it in my front end and if yes, then which specializes in the ref cursor which forces me to think that I can do this thing in a different way, so I have to use ref cursor

    What front end you intend to use?

    If you use .NET, Java etc. then you will need to use a ref Cursor to move the pointer to the request to the front end, so that it (the front-end server) can retrieve records through this slider and close when you are finished. If you retrieve records with any other cursor in the PL/SQL code, then you will have to gather up of all data in a kind of structure of table/collection before moving all that data to the front-end server. If you do this, it will consume a lot of memory on the Oracle server and then involve passing ALL that data to the front end, while the front-end server can only needed to pick up the first recordings of a few.

    REF CURSOR is the way to a 3rd party front-end to query the Oracle database. PL/SQL code, copy the following code already resides on the oracle database, and it can communicate directly with the database by using one of the other methods of the cursor.

  • problem with the collection and refcursor

    I have the 'ServerDisconnect2' function below. It should return as 'ref_cursor' on the parameter that is a data container of deleted rows slider, Java developers insist on using this type of data/collection. I don't know how to code to return the values of ID removed as 'ref_cursor '. See commented "open pDeleteList" - sentence, it is commented as does not compile.
    CREATE OR REPLACE PACKAGE oe_ctx AS
      TYPE gIntegerTable IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;
      TYPE cursor_type IS REF CURSOR;
    ....
    
      PROCEDURE ServerDisconnect2(pCasinoCode NUMERIC, pCasinoServerCode NUMERIC, pChannelServerCode CurrentLogins.ChannelServerCode%TYPE, pDeleteList OUT cursor_type) 
      IS
        vDeleteList oe_ctx.gIntegerTable;
      BEGIN
        DELETE FROM
        (
           SELECT cl.* FROM CurrentLogins cl, Accounts a
           WHERE cl.CasinoCode = pCasinoCode
           AND cl.CasinoServerCode = pCasinoServerCode
           AND cl.ChannelServerCode = pChannelServerCode
           AND cl.Code = a.code
           AND a.Type = 'lplayer'
           ORDER BY a.code
        ) RETURNING Code
          BULK COLLECT INTO vDeleteList;
          
    /*    OPEN pDeleteList FOR
          SELECT * FROM TABLE(vDeleteList);*/
          
        COMMIT;
      END ServerDisconnect2;
    Is it possible to convert the variable 'vDeleteList' in ref_cursor?
    So my only solution would be to open the ref_cursor BEFORE delete-clause with the same query delete clause has. But I'm afraid that then after opening the instant cursor after a milliseconds the deletion clause removes different lines and the procedure would be data incorrect in pDeleteList.

    Published by: CharlesRoos on August 26, 2010 06:10

    You need a collection of sql (created with CREATE TYPE...):

    I'll use the predefined collection sys.odcivarchar2list demonstation purposes:

    SQL> var cur refcursor
    
    SQL> declare
       ret_coll       sys.odcivarchar2list;
    begin
       delete from emp
         returning ename
              bulk collect into ret_coll;
    
       open :cur for select * from table (ret_coll);
    end;
    /
    PL/SQL procedure successfully completed.
    
    SQL> print
    
    COLUMN_VALUE
    -----------------------------------------------------------------------------------------------------------------------------
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER                                                                                                                       
    
    14 rows selected.
    
  • 2 refcursors within the same procedure using

    Hello
    Can we use 2 refcursors within the same procedure. This may seem strange. But I have a script to do so - one to dynamically check for some validations and another to return a result set.

    Yes, pass by the example below.

    CREATE OR REPLACE PACKAGE CURSPKG AS
    TYPE T_CURSOR IS REF CURSOR;
    PROCEDURE (EMPCURSOR ON T_CURSOR OPEN_TWO_CURSORS,
    DEPTCURSOR ON T_CURSOR);
    END CURSPKG;
    /
    CREATE OR REPLACE PACKAGE BODY CURSPKG AS
    PROCEDURE (EMPCURSOR ON T_CURSOR OPEN_TWO_CURSORS,
    DEPTCURSOR ON T_CURSOR)
    IS
    V_CURSOR1 T_CURSOR;
    V_CURSOR2 T_CURSOR;
    BEGIN
    V_CURSOR1 OPEN FOR SELECT * FROM EMP;
    V_CURSOR2 OPEN FOR SELECT * FROM THE DEPARTMENT;
    EMPCURSOR: = V_CURSOR1;
    DEPTCURSOR: = V_CURSOR2;
    END OPEN_TWO_CURSORS;
    END CURSPKG;
    /

    I hope that it would be useful.

Maybe you are looking for

  • Cannot read e-mail content, in my opinion, it is a problem encoding ISO-2022-KR

    I can't read Korean (even other languages) content of mail as attached images.It FAILED when I update to version 38.0.1.Is it a little changed? If I trun to display mode for the source of this e-mail message,It shows as below in the header, -= 00182E

  • I lost all of my contacts - why would it be - this happen

    When I tried to open my contacts, none were there.  However, when I send a new email to a person, e-mail address of this person is available.

  • DVD decoder

    How to installed decoder Dvd free of charge current massage dvd decoder is not installed?

  • DV6-6180se: the true features HP page!

    I have a computer laptop dv6-06180se, and I wanted to upgrade the ram to a 16 GB (8 X 8). When I opened the page on hp it says max = 8 GB ram. It is true that this is the max? Does this mean that if I replaced the with 16 GB of RAM, it will not use a

  • 0 x 00000024 reboot loop

    I rebooted Vista recently it was very slow, and it got stuck in a continuous reboot loop. Startup Repair also fails to load correctly and restarts until I can do something with it. They showed me a BSOD with an error message after turning off the aut