Ref Cursor on implicit and explicit cursors

Hello

In my company the drafting of PL/SQL procedure, everyone uses "Ref Cursor",
But the article below, said implicit is the best, then Explicit and Ref Cursor...

[http://www.oracle-base.com/forums/viewtopic.php?f=2 & t = 10720]

I'm a bit confused by this, can someone help me understand this?

Thank you

SeshuGiri wrote:

In my company the drafting of PL/SQL procedure, everyone uses "Ref Cursor",
But the article below, said implicit is the best, then Explicit and Ref Cursor...

[http://www.oracle-base.com/forums/viewtopic.php?f=2&t=10720]

I'm a bit confused by this, can someone help me understand this?

It has performance and it has performance...

To explain. There is one type of cursor in Oracle - that is the cursor which is analyzed and compiled by the SQL engine and stored in the shared the database pool. The "+ client +" then receives a handle (called a SQL statement handle of many APIs) that can be used to make reference to this slider in the SQL engine.

The performance of this slider is not determined by the customer. It is determined by the execution plan and how much enforcement of this slider cost ito of server resources.

The customer can be Java, VB, .net - or a PL/SQL program. This client language (SQL client), has its own structures dealing with this from the SQL engine cursor handle.

It can hide by the developer all together - so that they can't even see that there is a statement handle. That's what the implicit cursors in PL/SQL.

It can allow the developer to manually define the structure of slider - this is what the explicit cursors, ref Cursor and DBMS_SQL cursors in PL/SQL.

Each of these client cursor structures provides the programmer with a set of features to address different SQL cursor. Explicit cursor in PL/SQL constructs do not have the use of dynamic SQL statements. REF CURSOR and cursors DBMS_SQL do. REF CURSOR does not allow the programmer determine, at runtime, the structure of the projection of the cursor SQL. DBMS_SQL sliders do.

Only ref Cursor can be created in PL/SQL and then handed over to another client (for example, Java/VB) for treatment. Etc.

If each of the works of art/customer interfaces gives you a different feature for SQL cursors.

Choose the implicit cursors for example does not the SQL cursor move faster. The SQL engine does not know and does not care, which customer construct you use to deal with the SQL cursor handle, he gave you. It does not matter. It does not affect his performance of cursor SQL.

But on the client side, it can matter - if your code when dealing with that SQL cursor determines how fast your interaction with this SQL cursor is. How many context changes you make. How you use and reuse the SQL (for example hard vs soft analysis vs analysis reusing the same cursor handle). Etc.

Are there any unique client cursor construction which is better? N °

It's ignorant views. The customer's language provides a box tool, where each tool has a specific application. The competent developer will use the right tool for the job. The stupid developer will select a tool and use it as The Hammer to 'solve' all problems.

Tags: Database

Similar Questions

  • Explain implicit and explicit curesor for example?

    Explain implicit and explicit curesor for example?

    Is less than the example of implicit cursor belogs?

    Set serverout
    Start
    I'm in (select * from emp)
    loop
    dbms_output.put_line (i.empno);
    end loop;
    end;

    All THE SQLs are analyzed and stored and runs under the cursor. These are stored in shared SQL database Pool.

    You can view the contents of the shared pool (and sliders inside it) using the V$ SQLAREA and other views of virtual performance.

    The concept of a cursor implicit and explicit cursor is a concept of LANGUAGE - not a SQL concept. It depends on how this language (client) (PL/SQL or Java or C/C++ or Delphi or c# and Perl, etc.) implements its interface language for SQL cursors created in Shared Pool data.

  • Null implicit and explicit null

    Hi experts,

    I met two terms which is null implicit and explicit null and I were confused.

    anyone can try to explain what that means exactly by both of these terms.

    Implicit-null I understood - it's the last jump announce a lambel in 3 to indicate that it as implicit-null

    Please suggest

    Concerning

    Mahesh

    Hello

    Explicit and implicit null labels are generated by the router to the last jump to its neighbors.

    Implicit null is the default which means penultimate router must only send IP packet thus, it appears the label (the label known as PHP and it is done to reduce the load on the router of the last jump to burst). One of the drawbacks in implicit null approach is if the network is configured for QoS based on MPLS EXP bits, QoS is lost between the penultimate router and router the last jump.

    In this case, we can make use of Explicit null which means router penultimate jump does not jump label. It sends with the value of the label of 0 but with other areas including intact EXP bits. This way QoS treatment is kept between penultimate router and router the last jump. Explicit null value must be configured manually in the router of the last jump.

    HTH.

    Arun

  • Implicit vs explicit cursor

    Hello

    I read somewhere that the implicit cursor is used in the sql statement only returns a single line and explicit cursor is used when the sql statement returns several lines.
    I did not understand it. Why is it so? Can we not use cursor name when Sql returns multiple lines or explicit only one line?
    can someone explain this for example.

    Thank you
    AB

    AB312062 wrote:

    I read somewhere that the implicit cursor is used in the sql statement only returns a single line and explicit cursor is used when the sql statement returns several lines.

    Fake.

    I did not understand it. Why is it so? Can we not use cursor name when Sql returns multiple lines or explicit only one line?
    can someone explain this for example.

    Explicit cursor - allows you to set the cursor "overall" (e.g. pakage body) and reuse them several times in different procedures/functions in this package.

    Explicit cursor - allows you to bulk explicit code collect and have direct access to the collection.

    Implicit cursor - neither of the above is true, but the implicit cursor still has bulk of collection in the scenes, requires less code instructions to create (and no need to explicitly close the cursor either).

    An implicit cursor might look as follows:

    declare
      type TObjectNames is table of varchar2(30);
      names TObjectNames;
      name varchar2(30);
    begin
      --// single row fetch
      select object_name into name from user_objects where object_id = 123;
    
      --// bulk fetch
      select object_name bulk collect into names
      from user_objects where object_type = 'TABLE'
      order by 1;
    
      --// for loop
      for c in (
        select object_name bulk collect into names
        from user_objects where object_type = 'TABLE'
        order by 1
      ) loop
        do something with row c
      end loop;
    end;
    
  • 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.

  • 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

  • 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

  • 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.

  • 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

  • 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;

  • REF CURSOR output and race update

    Hello

    I have a process where I need to make changes in quantity for the products. I want to these products and the quantity of output in a c# application and also update my table of inventory with the new values.

    My question is what is the best way to have a stored procedure out a REF CURSOR (for the purposes of c#) and use the same data that came out in the REF CURSOR to update my table of inventory?

    I have this:

    -USE IT TO GET MY PRODUCTS-
    PROCEDURE sp_get_products)
    r_products ON SYS_REFCURSOR
    )

    IS

    BEGIN

    Select ProductID, InStock
    Products

    END sp_get_products;


    -USE CE TO OUTPUT REF CURSOR and run - UPDATE
    PROCEDURE sp_get_ref_products)
    r_ref_products ON SYS_REFCURSOR
    )

    IS

    type ProductID is the Products.ProductID%type table;
    QTY type is table of the Products.QTY%type;

    l_ProductID ProductID;
    l_QTY QTY;

    BEGIN
    sp_get_products (r_ref_products);

    Get the r_ref_products COLLECT in BULK IN l_ProductID, l_QTY;
    ForAll indx l_ProductID.first... l_ProductID.Last
    Update product p
    Set p.QTY = l_QTY (indx)
    Where p.ProductID = l_ProductID (indx);

    COMMIT;


    END sp_get_ref_products;

    Maybe you're not understanding what is a Ref Cursor. It does not store a result set.

    Take a read of this thread:

    [PL/SQL 101: understanding Ref Cursor | http://forums.oracle.com/forums/thread.jspa?threadID=886365&tstart=0]

  • 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

  • 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>
    
  • Ref Cursor and type

    Hi all

    I finally got the job of procedure stored Ref Cursor but am stuck on the following. I have this package body:

    CREATE OR REPLACE PACKAGE BODY PACK_MYCURSOR AS
    PROCEDURE REFCUR)
    theuserid IN OUT users.user_id%type,
    UserFirstName to users_TableRows) IS
    BEGIN
    OPEN FOR UserFirstName
    Select * from users
    Where user_id = theuserid
    ;
    END REFCUR;
    END PACK_MYCURSOR;
    /

    Now it works fine, but I need to have fields of explisit in the select statement, such as "select user_id from users", but when I do that then I would get the error messages of "expression is of the wrong type." Someone knows how to fix this?

    Thank you.

    Declare your as WEAK rather than STRONG type ref cursor. In other words, do not specify return rowtype % ROWTYPE in your statement in the specification.

    Declare that:
    TYPE users_TableRows IS REF CURSOR;

    Phil

Maybe you are looking for