Ref Cursor, object variable and cusror Cursor

Hello Experts,

I am little confused with the concept of cursor objects

For the variable curosr we can attribute any select statement

For example

Suppose that I assigned 2 Select staemnt to same variable as open c1 cursor for select * Dept, then I m posting new query without closing the c1 open c1 for select * from emp what will happen? What is the role of the object cursor here? I'm really confued thereby as cursor variable points to the result set? Can you please explain how same variable works with differnet queries? We hear how even variable points to the differnet result sets thank you very much in advance, SShubhangi

I am little confused with the concept of cursor objects

Post a link to the Oracle documentation, you are using and a quote from the section that you are confused about.

For the variable curosr we can attribute any select statement

Yes - as you can put a small yellow "sticky notes" on your refrigerator or Cabinet you or on your stove. Stick to what you want - but you can only stick on ONE element at a time.

For example

Suppose that I assigned 2 Select staemnt to same variable as open c1 cursor for select * Dept, then I m posting new query without closing the c1 open c1 for select * from emp what will happen?

What happened when you tried?

Do not be afraid to break the Oracle actually trying things. It's the best way to learn.

Try what you said and post the results.

I'm really confued thereby as cursor variable points to the result set? Can you please explain how same variable works with differnet queries? We hear how same variable points to the results of differnet games

Re-read what I said just above.

Then explain how you can "point" that yellow "sitcky note" any object you want. You can put on a single object. Then you can remove this object and put it on another object.

But no matter how many times do you it can only stick to ONE object at a time.

What is confusing in this regard?

See the PL/SQL language for the OPEN statement doc

http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/open_statement.htm#i35173

As a general rule, PL/SQL analysis a cursor explicit only the first time it is opened and analysis a SQL (creating an implicit cursor) only the first time the statement is executed. All the parsed SQL statements are cached. An SQL statement is parsed once again if it is aged in the cache by a new SQL statement. Although you must close a cursor before you can reopen, PL/SQL cannot analysis associated with SELECT statement. If you close and reopen the cursor immediately, an analysis is certainly not necessary.

Did you notice the line that begins: "Although you must close a cursor before you can reopen?

Tags: Database

Similar Questions

  • Insert data from variables in the Ref Cursor

    I do not know how to return data from ref cursor variables That's what I've tried so far...
    CREATE OR REPLACE type num_obj as object (
      t_number number ,
      t_type varchar2(10) ,
      t_desc varchar2(40)
    ); 
    CREATE OR REPLACE type num_table as table of num_obj; 
    
    procedure get_all_data(p_p1 in varchar2, p_rc OUT SYS_REFCURSOR) is
       l_dat1 number := 2;
       l_dat2 varchar2(10);
       l_dat3 varchar2(40);
       t_num_o num_obj;
       t_num_t num_table;
    begin
      for l_indx in 1..5 loop
         l_dat1 := l_dat1 + l_indx;
         if ( mod(l_dat1,2)=0) then
           l_dat2 := 'EVEN';
         else
           l_dat2 := 'ODD';
         end if;
         l_dat3 := 'Number ' || l_dat1 || ' is ' || l_dat2 || ' number'; 
         l_num_o := num_obj (l_dat1, l_dat2, l_dat3);
         l_num_t := num_table(l_num_o);
      end loop;
      open p_rc for select * from table(l_num_t);
      close p_rc;
    end;
    At the end, to achieve this in Ref Cursor:
    t_number | t_type | t_desc
    ---------------------------------------
    3        | ODD    | Number 3 is ODD number
    5        | ODD    | Number 5 is ODD number
    8        | EVEN   | Number 8 is EVEN number
    12      | EVEN    | Number 12 is EVEN number
    17      | ODD     | Number 17 is ODD number
    Can something like that, where I did wrong?

    BTW. I did this with the function in pipeline, now I want to try a different method.

    The refcursor can not be closed in the procedure - you must return refcursor open to the appellant.
    the appellant must read and then close it.
    There are also some errors in the names of variables and an assignment to the collection.

    Try this version:

    CREATE OR REPLACE
    PROCEDURE GET_ALL_DATA(P_P1 IN VARCHAR2, P_RC OUT SYS_REFCURSOR) IS
       l_dat1 number := 2;
       l_dat2 varchar2(10);
       L_DAT3 VARCHAR2(40);
       L_NUM_O NUM_OBJ;
       l_num_t num_table := num_table() ;
    BEGIN
      for l_indx in 1..5 loop
         l_dat1 := l_dat1 + l_indx;
         if ( mod(l_dat1,2)=0) then
           l_dat2 := 'EVEN';
         else
           l_dat2 := 'ODD';
         end if;
         l_dat3 := 'Number ' || l_dat1 || ' is ' || l_dat2 || ' number';
         L_NUM_O := NUM_OBJ (L_DAT1, L_DAT2, L_DAT3);
         L_NUM_T.EXTEND;
         l_num_t( l_indx ) := l_num_o;
      end loop;
      OPEN P_RC FOR SELECT * FROM TABLE(L_NUM_T);
    END;
    /
    
    SQL> variable xx refcursor
    SQL> execute GET_ALL_DATA( '', :xx );
    
    PL/SQL procedure successfully completed.
    
    SQL> print :xx
    
      T_NUMBER T_TYPE     T_DESC
    ---------- ---------- ----------------------------------------
          3 ODD           Number 3 is ODD number
          5 ODD           Number 5 is ODD number
          8 EVEN       Number 8 is EVEN number
         12 EVEN       Number 12 is EVEN number
         17 ODD           Number 17 is ODD number
    
  • Call a procedure stored via JDBC with a REF CURSOR * input variable.

    Hello

    S/n of my client has provided me with a stored procedure that I need to call to get information about products prices. Something along the lines of:

    some_package.getPrices (products IN OUT csr_type);

    where csr_type represents a REF CURSOR. This cursor has a product ID column and a price column. The plan is to move the cursor with the populated product id column and have the routine decorate the slider with the prices.

    The setting in this plan is that it seems that it is not possible to go from JDBC REF CURSOR in . However, I'm not sure, since I can only find throw comments on various forums (e.g. http://www.orafaq.com/forum/t/35088/0/), without any reference. If I go back to the client and tell them that their idea will not work, I prefer to be able to point them to a documentation somewhere

    So I guess my questions are:

    1. it is indeed impossible to pass a REF CURSOR type as a variable input on JDBC to a stored procedure?

    2. is there information I can do about my client?

    3. am I on the right track thinking I need to go down the path of an array of objects?

    Thank you very much to anyone who can help
    Peter Svehla.

    Hi Peter,.

    I see it, missed that you actually want to pass in a list of products. Don't think that you can do this with the current procedure. A slider is just a pointer to a result set.
    How the result set is created and what it looks like, is determined when the cursor is opened.

    What does this procedure with the cursor? -It does not have some OPEN TO ; inside?

    Or, perhaps, you are supposed to send in an open cursor (does not much sense to me)?

    Concerning
    Peter

  • Casting table PL/SQL for the type of existing table and back ref cursor

    Hello



    I have the problem of casting a pl/sql table for the type of an existing table and turning the ref cursor to the application. Casting a ref cursor back and number of pl/sql table works well.



    Declarant

    < strong > TYPE type_table_name IS TABLE OF THE package_name.table_name%ROWTYPE; < facilities >

    within the stored procedure, fill in a table of this type temp_table_name and returning the ref cursor help

    < strong > results OPEN to SELECT * FROM TABLE (CAST (temp_table_name AS type_table_name)); < facilities >

    generates an error. type_table_name is unknown in this distribution. According to me, this happens because of the declaration of the type locally.



    Statement type_table_name inside the package specification does not work neither. Incredible, cast to the said dbms_sql.number_table to specify ref cursor back and dbms_sql package works very well!



    < strong > CREATE TYPE type_table_name IS TABLE OF THE package_name.table_name%ROWTYPE; < facilities > deals without any error but creates an invalid type complain a reference to package_name.table_name



    I don't want to declare every column in the table in type_table_name, because any change the table_name table would result in an inconsistent type_table_name.



    Thanks in advance!

    Edited by: user6014545 the 20.10.2008 01:04

    In any case you are right that there is a problem around anchorage (or maintaining) types of objects persistent to match the table structures, they may represent.

    In the case you describe, you might be better off just open the refcursor immediately the using one of the techniques described in the http://www.williamrobertson.net/documents/comma-separated.html to manage the delimited list.

    In the more general case where the line of treatment is necessary, you may make the pipeline functions.

    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    
    SQL> CREATE TABLE table_name
      2  AS
      3     SELECT ename column_name
      4     FROM   emps;
    
    Table created.
    
    SQL> CREATE OR REPLACE PACKAGE package_name
      2  AS
      3     TYPE type_name IS TABLE OF table_name%ROWTYPE;
      4
      5     FUNCTION function_name_pipelined (
      6        parameter_name IN VARCHAR2)
      7        RETURN type_name PIPELINED;
      8
      9     FUNCTION function_name_refcursor (
     10        parameter_name IN VARCHAR2)
     11        RETURN sys_refcursor;
     12  END package_name;
     13  /
    
    Package created.
    
    SQL> CREATE OR REPLACE PACKAGE BODY package_name
      2  AS
      3     FUNCTION function_name_pipelined (
      4        parameter_name IN VARCHAR2)
      5        RETURN type_name PIPELINED
      6     IS
      7     BEGIN
      8        FOR record_name IN (
      9           SELECT table_alias.*
     10           FROM   table_name table_alias
     11           WHERE  table_alias.column_name LIKE parameter_name) LOOP
     12
     13           PIPE ROW (record_name);
     14        END LOOP;
     15
     16        RETURN;
     17     END function_name_pipelined;
     18
     19     FUNCTION function_name_refcursor (
     20        parameter_name IN VARCHAR2)
     21        RETURN sys_refcursor
     22     IS
     23        variable_name sys_refcursor;
     24     BEGIN
     25        OPEN variable_name FOR
     26           SELECT table_alias.*
     27           FROM   TABLE (package_name.function_name_pipelined (
     28                     parameter_name)) table_alias;
     29
     30        RETURN variable_name;
     31     END function_name_refcursor;
     32  END package_name;
     33  /
    
    Package body created.
    
    SQL> VARIABLE variable_name REFCURSOR;
    SQL> SET AUTOPRINT ON;
    SQL> BEGIN
      2     :variable_name := package_name.function_name_refcursor ('%A%');
      3  END;
      4  /
    
    PL/SQL procedure successfully completed.
    
    COLUMN_NAME
    -----------
    ALLEN
    WARD
    MARTIN
    BLAKE
    CLARK
    ADAMS
    JAMES
    
    7 rows selected.
    
    SQL> ALTER TABLE table_name ADD (new_column_name VARCHAR2 (1) DEFAULT 'X');
    
    Table altered.
    
    SQL> BEGIN
      2     :variable_name := package_name.function_name_refcursor ('%A%');
      3  END;
      4  /
    
    PL/SQL procedure successfully completed.
    
    COLUMN_NAME NEW_COLUMN_NAME
    ----------- ---------------
    ALLEN       X
    WARD        X
    MARTIN      X
    BLAKE       X
    CLARK       X
    ADAMS       X
    JAMES       X
    
    7 rows selected.
    
    SQL>
    
  • Apex and accept Ref Cursor?

    Apex and accept Ref Cursor?

    Apex and accept objects?

    can someone help me please.

    Hi Nani4850,

    Nani4850 wrote:

    Apex and accept Ref Cursor?

    Apex and accept objects?

    The language of business for APEX is PL/SQL, so yes you can use REF CURSOR and pass objects to you packaged functions/procedures.

    How does this relate to Oracle APEX?

    Please explain what you plan to use a REF CURSOR in the APEX.

    Kind regards

    Kiran

  • sys_refcursor and Ref Cursor

    Hello

    I found this diffrence between ref and sys_refcursor slider.

    If you specify return_type, then the variables of type and slider REF CURSOR of this type are strong; If not,
    they are weak.
    The variables SYS_REFCURSOR and slider of this type are weak.

    my situation is that I must write a procedure stored so many reports entery pages. little enter pages use typed data groups and can't.

    so please tel me what is the best in terms of performance and maintainability above three conditions?

    Yours sincerely

    944768 wrote:

    my situation is that I must write a procedure stored so many reports entery pages. little enter pages use typed data groups and can't.

    Called stored procedures what and where?

    If, with a layer of app such as Java or .net, then they do not distinguish between weak and strong ref Cursor - because it is a concept of PL/SQL.

    And by using a ref cursor type in PL/SQL is intended to provide a mechanism to pass the handle of real cursor SQL cursor created in this session, the client (for example Java or .net). Nothing more. So, why even care that PL/SQL? a weak or strong Ref to the application layer slider

    so please tel me what is the best in terms of performance and maintainability above three conditions?

    I find always frustrating that there is this concept that some methods to create cursors, results in faster and better than other methods, the sliders. It is a concept of bs. All SQLs are analyzed as a SQL cursors. Each. Unique. One. By the SAME CBO.

    If the client code (Java, PL/SQL or other) you write for this SQL cursor DOES NOT change the source SQL.

    This therefore does not cause the CBO now compile a different SQL execution plan for her. The CBO does not care if your code uses a strong Ref Cursor or a weak Ref Cursor, or a slider DBMS_SQL, an explicit cursor, or whatever. Those are concepts of customer. And do not change the execution plan of cursor SQL on the server. Or its planned performance/cost.

    Yes, your client code (Java, PL/SQL, etc.) can use the SQL cursor on the server-side evil - and this can affect performance.

    But waiting for a weak Ref cursor will somehow cause a faster cursor or slower for the same SQL statement, that a strong Ref cursor is not understanding what SQL cursor is, and how the customer interacts with its data types, the classes of customers and its customer interfaces with this SQL cursor.

  • The use of bind variables in dynamic query created for Ref Cursor

    Hello

    I'm in a situation where there is a Ref cursor to which the query is built execution based on a loop. This is why the number of links would be known until the program runs.
    The application is currently using literals instead of bind variables.

    code snippet of the above is
    strSql: = "select * from emp where 1 = 1 and ().

    loop cursor1
    If cond is true then
    strSql = strSql | "ename = ' |" Cursor1.ColumnName;
    end loop;

    Open cursor2 for strSql;

    How to use links in the example above.

    sb92075 wrote:

    user13019948 wrote:
    Hello

    Here is the code I have my trying to change literal-based link to the base.

    What do you mean by "based bind?

    who, what, how determines the values to be 'bound '?

    He's referring to the coding style. He is currently using concatenated literal, and the goal is to change it to use the bindings.

    If I understand this it is known as method 4 dynamic SQL and requires DBMS_SQL. There are examples autour but they vary according to the type of statement being generated - SELECT statements require column lists to be parsed, unlike the INSERT/UPDATE/DELETE.

    This came up recently on my current project and I hit a demo. Here a table of names and values accepted procedure and had to build these in a single WHERE clause along the lines of

    AND t_names(i) = t_values(i)
    

    for an undetermined number of elements in the array. For this demonstration, I used a table that we called "attribute" (don't ask) which has columns including 'attribute_id' and 'name', and I need to build a query along the lines of

    select description from attribute where attribute_id = :b1 and name = :b2
    

    by the way '1012' and 'ISIN' respectively. (I use a table better and after a CREATE statement for her but I have to rush right now, sorry).

    declare
       k_sql_base        constant varchar2(500) := 'select description from attribute';
    
       t_names           constant varchar2_t := varchar2_t('attribute_id',  'name');
       t_values          constant varchar2_t := varchar2_t('1012',          'ISIN');
    
       l_sql             varchar2(500) := k_sql_base;
       l_rows_fetched    integer := 0;
       l_value           varchar2(4000);
    
       l_cursor_handle   integer;
    
    begin
       -- Construct the SQL statement with column names and bind variables e.g.
       -- 'select description from mars.attribute where attribute_id = :b1 and name = :b2'
       for i in t_names.first .. t_names.last loop
          l_sql := l_sql ||
             case i
                when t_names.first then ' where ' else ' and '
             end ||
             t_names(i) || ' = :b' || i;
       end loop;
    
       dbms_output.put_line('SQL statment = ' || l_sql); 
    
       -- Parse the statement we built above (the remaining steps require a parsed cursor):
       l_cursor_handle := dbms_sql.open_cursor;
       dbms_sql.parse(l_cursor_handle, l_sql, dbms_sql.native);
    
       -- Associate the 1st column of output with variable l_value - required for SELECT statements:
       -- (actually the 3rd param here 'column' seems to be only used to get a datatype, in this case we want a string -
       -- dbms_sql.column_value actually extracts the value into a specified variable, which can be different.
       -- All examples in the documentation pass a local variable without further comment, so not entirely clear what this does other than set the output datatype.)
       dbms_sql.define_column(l_cursor_handle, 1, l_value, 4000);
    
       -- Now go through values array binding actual values to :bn variables in the cursor (similar to USING clause of EXECUTE IMMEDIATE)
       for i in t_values.first .. t_values.last loop
          dbms_sql.bind_variable(l_cursor_handle, ':b'||i, t_values(i));
          dbms_output.put_line('Bound :b'||i || ' as ' || t_values(i));
       end loop;
    
       -- Open the cursor and fetch the result (no loop here because we are expecting a single-row result):
       l_rows_fetched := dbms_sql.execute_and_fetch(l_cursor_handle);
    
       -- 'Returns value of the cursor element for a given position in a cursor'
       -- Copy the value of column 1 to variable l_value (has to match
       -- dbms_sql.column_value(l_cursor_handle, 1, l_value);
       dbms_sql.column_value(l_cursor_handle, 1, l_value);
    
       dbms_output.put_line('Result = ''' || l_value || '''');
    
       dbms_sql.close_cursor(l_cursor_handle);
    end;
    

    Hope that helps...

  • using plsql table and ref cursor in oracle's 10 g

    Hi all
    Can someone give me an example of a scenario where we need to create a form manually based on a stored database procedure.
    And in this process, I created a pl/sql table and a Ref cursor at the database level.

    CREATE OR REPLACE PACKAGE SCOTT. TYPE BONUS_PKG IS bonus_rec
    IS (RECORD
    EmpNo bonus_EMP.empno%TYPE,
    Ename bonus_EMP.ename%TYPE,
    employment bonus_EMP.job%TYPE,
    SAL bonus_EMP.sal%TYPE,
    Comm bonus_EMP.comm%TYPE);

    TYPE b_cursor IS REF CURSOR RETURN bonus_rec;
    TYPE bontab IS TABLE OF bonus_rec INDEX DIRECTORY.

    PROCEDURE bonus_refcur (bonus_data IN OUT b_cursor);
    PROCEDURE bonus_query (bonus_data IN OUT bontab);
    END bonus_pkg;


    CREATE OR REPLACE PACKAGE BODY SCOTT. BONUS_PKG IS
    PROCEDURE bonus_query (bonus_data IN OUT bontab) IS
    II NUMBER;
    CURSOR bonselect IS
    SELECT empno, ename, job, sal, comm bonus_EMP ORDER BY empno;
    BEGIN
    OPEN bonselect.
    II: = 1;
    LOOP
    Look FOR bonselect IN
    .EmpNo bonus_data (ii),
    .ename bonus_data (ii),
    .job bonus_data (ii),
    .Sal bonus_data (ii),
    .comm bonus_data (ii);
    EXIT WHEN bonselect % NOTFOUND;
    II: = ii + 1;
    END LOOP;
    END bonus_query;

    PROCEDURE bonus_refcur (bonus_data IN OUT b_cursor) IS
    BEGIN
    Bonus_data OPEN to SELECT empno, ename, job, sal, comm bonus_EMP ORDER BY empno;
    END bonus_refcur;

    END bonus_pkg;

    I want to fill in the data in the forms manually is not using Forms data block Wizard and by program.

    Please answer...

    Can someone give me an example of a scenario where we need to create a form manually based on a stored database procedure.

    In general, you will use a block of proceedings based when you have a collection of data from several tables presented in a form and your username must be able to update the information displayed.

    In your sample code, looks like you are using Oracle Support document "Melting a block on a Stored Procedure - examples of Code [ID 66887.1]". If this is the case, continue to follow the document - it guides you through all the steps. There is no need to manually configure things that the data block Wizard will work for you!

    I want to fill in the data in the forms manually is not using Forms data block Wizard and by program.

    Why? Let the wizard block configuration data of your block based on a procedure for you. There is no need to manually browse the data! I did what you're trying, and it's more work needed. Leave forms to do the work for you. :)

    If you absolutely have to do things manually, I recommend that you use the PROCEDURE bonus_query (bonus_data IN OUT bontab) instead of bonus_refcur (bonus_data IN OUT b_cursor) . Then, in your code create a variable of type BONTAB, and then call the bonus_query procedure. Then, it's a simple case of a loop in the table of records returned by the bonus_query procedure. For example:

    DECLARE
       t_bonus    bonus_pkb.bontab;
    BEGIN
       bonus_pkg.bonus_query(t_bonus);
    
       FOR i in 1 .. t_bonus.count LOOP
          :YOUR_BLOCK.EMPLOYEE_NUMBER := t_bonus(i).empno;
          :YOUR_BLOCK.EMPLOYEE_NAME := t_bonus(i).ename;
          :YOUR_BLOCK.EMPLOYEE_JOB := t_bonus(i).job;
          :YOUR_BLOCK.EMPLOYEE_SALARY := t_bonus(i).sal;
          :YOUR_BLOCK.EMPLOYEE_COMMISSION := t_bonus(i).comm;
       END LOOP;
    END;
    

    This code example shows the basics, but as is the sample code - you will need to adapt to your situation.

    Also, I highly recommend that you look at the article inol listed. It is a very thorough debate on the REF CURSOR. If you have set up using a procedure based on the data source - it is more effective to spend the record table to your form that it must pass a ref cursor Using a ref cursor, you might as well just using a standard called cursor and loops on your named cursor. The effect is the same (a line returned at the same time creating lots of network traffic). Using the table of records is more efficient because the data set is returned if the network traffic is reduced.

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

  • Example of using a Ref Cursor variable procedure

    I'm looking for an example of how to execute a stored procedure with a Ref cursor variable in SQL Developer 3.0. I am familiar with the syntax in SQL * Plus, for example:

    variable my_cur refcursor;
    Start
    my_package.my_proc ("in param"
    (: my_cur);
    end;
    /

    print: my_cur

    How would I do the same thing in SQL Developer 3.0?
    Thank you!

    Run a procedure directly. For example, select the package in the browser-> menu-> Run. The dialogue with anonymous block box. Edit, OK it to run, then the procedure would be and all settings including Ref Cursor appear in the grid. (This functionality is there since 3.0)

  • REF CURSOR Vs objects

    Hi all

    I'm working on Oracle 10 g. e could migrate to 11g in the coming months, our front end is with .net.

    I have a few scenarios where I pass the end before a set of values... (sometimes a few 100 and sometimes some 1000s)

    On what basis should I decide to go with the REF cursor or with objects...

    Is there a particular scenario where I can adapt REF CURSOR Type and objects...


    Appreciate your help and your sugessions

    Thanks in advance
    M

    Mandatory AskTom references:

    The use of collections of Oracle and result sets
    PL/SQL API for Java/VB - tables to return data or result sets

  • Need the difference between strong Ref Cursor and weak Ref Cursor examples

    Oracle 9.2

    It would be great if someone can help understand the differences between
    1 Strong Ref Cursors(return type)
    and
    2. weak Ref Cursor (no return type)

    What I read is weak ref Cursor as sys_refcursor is better to use the ref Cursor, because in the case of slider strong Ref object type that will be returned must be declared in advance. It dosent make sense to me?

    I start with the examples would be appreciate for advice

    Strong Ref Cursor

    create the package str_pack
    is
    type sref_type is ref cursor return emp % rowtype;
    SVAR sref_type;
    end str_pack;

    Create procedure st_proc (eid in number, c1 on str_pack.sref_type)
    is
    Start
    Open c1 to select empno, ename, sal from emp where empno = eid;
    end;

    declare
    str_pack.sref_type C1;
    type rec is RECORD (eid, ename varchar2 number (20), number of sal);
    SheikYerbouti rec;
    Start
    st_proc(10,C1);
    loop
    When exit c1% notfound;
    Fetch c1 into SheikYerbouti.
    end loop;
    Close c1;
    end;


    There could be errors in the above example but its basically to get a better understanding.

    For weak Ref Cursor

    procedure of the child

    Create procedure child_proc (in number, c1 on sys_refcursor eid)
    is
    Start
    Open c1 to select empno, ename, sal from emp where empno = eid;
    end;

    parent process

    Create procedure parent_proc (recnum varchar2)
    is
    p_retcur sys_refcursor;
    emp_row emp % rowtype;
    Start
    child_proc (eid, p_retcur);
    loop
    extract the p_retcur in emp_row;
    dbms_output.put_line(emp_row.empno ||) e '|| emp_row. Ename | "wins". emp_row. SAL);
    end loop;
    end parent_proc;

    Concerning
    @

    Hello

    the fundamental difference is to do with the compiling and linking of runtime type that occurs.

    The he should explain a lot more detail than I could ever!
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1640161160708

    P;

  • 2 running, 1 inside and 1 sql external, dynamic queries using loops and ref Cursor

    Hi all

    I'm under Oracle 10.2.0.2. I'm currently building dynamic sql using external and internal queries ref Cursor. Queries make use of user selected lists of ID, which is stored in a table in memory at run time. My example is as follows. From a list of book_publication_id on a web page, the user selects several books. The same user selects then several maps from a list of map_publication_id on the same web page. A book contains several maps and some of these cards will appear in more than one book (aka many many relationships).

    This should then ask the following output to a new web page:
    Outer loop:  Display book details for book_publication_id 230
      Inner loop:  Display 1st map details for map_publication_id 340
      Inner loop:  Display 2nd map details for map_publication_id 346
      Inner loop:  Display 3rd map details for map_publication_id 350
    Outer loop:  Display book details for book_publication_id 240
      Inner loop:  Display 1st map details for map_publication_id 346
      Inner loop:  Display 2nd map details for map_publication_id 375
    Outer loop:  Display book details for id 255
    and so on.
    In the example above, the outer loop displays the details of the book for book_publication_id 230 and the inner loop displays all the users selected the maps in book_publication_id 230. Then, it moves on the details of the book for book_publication_id 240 and done the same thing again. Similar in some ways to how break would work in SQL * Plus, even if the table is built like an HTML, the book details must be on a separate line for the card details. However I don't know how I would want it to work.

    So far, using loops, I could not show all the details of card for each different book_publication_id, after the details of the book for only 1 book_publication_id are displayed each time. If a loop in a loop. I hope that makes sense. I think this is my internal request that it be built differently. My code for this part of the program, which is currently wrong, is as follows:
    --Global variable section contains:
    var_user_chosen_map_list_ids VARCHAR2(32767);
    var_details VARCHAR2(32767);
    ......
    PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST)
    IS
    BEGIN
    FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count
    LOOP
       var_user_chosen_map_list_ids := var_user_chosen_map_list_ids || 
       '''' || 
       par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) || 
       ''',' ;
    END LOOP;
     var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids,
                                            1, 
                                            length(var_user_chosen_map_list_ids)-1);
    var_details := FUNCMAPDATAFIND (var_user_chosen_map_list_ids);
    htp.print(var_details);
    END PROCMAPSEARCH;
    FUNCTION FUNCMAPDETAILS (par_user_chosen_map_list_ids IN VARCHAR2(32767)
    RETURN VARCHAR2
    AS
    TYPE cur_type_map IS REF CURSOR;
    cur_book_search cur_type_map;
    var_book_date NUMBER(4);
    var_book_title VARCHAR2(32767);
    cur_map_search cur_type_map;
    var_map_date NUMBER(4);
    var_map_title VARCHAR2(32767);
    begin:
    OPEN cur_book_search FOR
    'SELECT BI.book_date,
            BT.book_title
     FROM   BOOK_INFO BI,
            BOOK_TITLE BT,
            TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_book_list_ids || ')) BL_1
     WHERE BI.book_title_id = BT.book_title_id
     AND BI.book_publication_id = BL_1.column_value';
    OPEN cur_map_search FOR
    'SELECT MI.map_date,
           MT.map_title
    FROM map_info MI,
         map_title MT,
         TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_book_list_ids || ')) BL_2
         TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_map_list_ids || ')) ML
    WHERE MI.map_title_id = MT.map_title_id
    AND BI.book_publication_id = BL_2.column_value
    AND BI.book_publication_id = MI.pub_publication_id
    AND MI.map_publication_id = ML.column_value';
    LOOP
    LOOP
    FETCH cur_map_compare INTO
    var_book_date,
    var_book_title;
    var_details
    var_details := var_details || 'Book date: '||
                        var_book_date ||
                        'Book title: ' ||
                        var_book_title;
    FETCH cur_map_compare INTO
    var_map_date,
    var_map_title;
    var_details := var_details || 'Map date: '||
                        var_map_date ||
                        'Map title: ' ||
                        var_map_title
    EXIT WHEN cur_book_compare%NOTFOUND;
    END LOOP;
    EXIT WHEN cur_map_compare%NOTFOUND;
    END LOOP;
    RETURN var_details;
    END FUNCMAPDETAILS;
    If anyone has any ideas or suggestions, I would be grateful. It is an extension of my previous code, I posted a question recently. As I am working and learning a step at a time, I left this idea in my previous question, that I had to make sure I knew that first.

    Kind regards

    Tim

    Using dynamic SQL

    declare
      dd sys_refcursor;
      ee sys_refcursor;
      d dept%rowtype ;
      e emp%rowtype ;
    begin
    open dd for 'select * from dept' ;
    loop
    fetch dd into d ;
    exit when dd%notfound ;
    dbms_output.put_line('Department:'||d.dname);
      open ee for 'select * from emp where deptno='||d.deptno ;
      loop
      fetch ee into e ;
      exit when ee%notfound ;
      dbms_output.put_line('..Employee:'||e.empno||':'||e.ename);
      end loop;
    end loop ;
    end ;
    /
    Department:ACCOUNTING
    ..Employee:7782:CLARK
    ..Employee:7839:KING
    ..Employee:7934:MILLER
    Department:RESEARCH
    ..Employee:7369:SMITH
    ..Employee:7566:JONES
    ..Employee:7788:SCOTT
    ..Employee:7876:ADAMS
    ..Employee:7902:FORD
    Department:SALES
    ..Employee:7499:ALLEN
    ..Employee:7521:WARD
    ..Employee:7654:MARTIN
    ..Employee:7698:BLAKE
    ..Employee:7844:TURNER
    ..Employee:7900:JAMES
    Department:OPERATIONS
    
    PL/SQL procedure successfully completed.
    

    HTH

    SS

  • differnce between Ref Cursor strong and weak Ref Cursor

    differnce between Ref Cursor strong and weak Ref Cursor

    SQL and PL/SQL FAQ

    -------------
    Sybrand Bakker
    Senior Oracle DBA

  • What is the difference between the ref cursor and the sys_refcursor.

    create or replace procedure GetEmployeesInDept (c sys_refcursor)

    Hello


    I have a query related to the above stored procedures.
    When you set the cursor, we mentioned as sys_refcursor and in some US sites I saw him as a REF CURSOR as shown

    create or replace procedure GetEmployeesInDept (Ref Cursor c)


    Please tell me what is the difference between the ref cursor and the sys_refcursor.

    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/tuning.htm#sthref2376

    Concerning

    Etbin

  • Packages and poorly Ref Cursor

    SQL Server Developer, I fight with Oracle to say the least. I fought with the poor performance of the extraction of data from the database, but also a multitude of other things. The last number I have is a stored procedure in a package that does not work when run from my .NET code. I have many other packages and stored procedures that are working, but this one is a failure. I don't get any errors, just no data when I should be.

    I would run the toad package and see if it is the stored Proc and packaging, or if there is a problem in my .NET code. My stored procedure accepts a single PARAMETER of type integer, and has two parameters SYS_RefCursor OUT. My SQL uses the parameter (ID field) to select from a table. If I run the select SQL by itself with the hardcoded value ID, it works fine. I can run too where it uses the SQL for open cursors and inserts the data but I can't determine if it worked.

    So, my questions are the following:

    Can I select a Ref_Cursor? I'm trying to do something like that.
    results_cursor SYS_REFCURSOR;
    
    OPEN results_cursor FOR
       SELECT * FROM Person;
    
    SELECT * FROM results_cursor;
    If I could get the 1st issue a response, I can keep up with my next question.

    Thanks in advance.
    Jeff

    Hello

    I don't see an issue of .NET at this point, so you can have the best chance to post in the forum PLSQL, as it seems that if you need help writing a procedure, rather than interacting with a procedure well known in .NET:
    SQL and PL/SQL

    I'm not clear on your question though. Yes, you can read from a slider ref, and you do it by getting him.

    SQL > set serveroutput on

    SQL > declare
    Ref1 2 sys_refcursor;
    3 rec1 emp % rowtype;
    Number 4 NTC;
    5. start
    6. open ref1 for select * from emp;
    7 LOOP
    8 FETCH INTO rec1 ref1;
    9 OUTPUT WHEN ref1% NOTFOUND;
    10 DBMS_OUTPUT. Put_line (' name = ' | rec1.ename);
    11 END OF LOOP;
    12 end;
    13.
    Name = SMITH
    Name = ALLEN
    Name = WARD
    Name = JONES
    Name = MARTIN
    Name = BLAKE
    Name = CLARK
    Name = SCOTT
    Name = KING
    Name = TURNER
    Name = ADAMS
    Name = JAMES
    Name = FORD
    Name = MILLER

    PL/SQL procedure successfully completed.

    SQL >

    Maybe if clarify what you are trying to do or accomplish in "selecting from a ref cursor" it would be useful.

    Greg

Maybe you are looking for