Refcursor and Normal Cursor

Hi Folks,
As per my understanding there is no performance wise difference between the normal cursor and ref cursor the only difference is that only through the help of the refcur we can return the result set to the calling env or calling procedure.
But in OTN site one of the excerpts from Tom I came across a statement that the refcursors can not be global means we can not declare the refcur in the package specification
the link is http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541
but many times in my project we have declaree the refcursor in the package specifications also
Can any one explain me what Tom really meant by that statement or whether I am misinterpreting the statement
Any suggestions will be highly appreciated
Thanks in advance
Prafulla

Prafulla wrote:
Please clarify me cause I am not able to make it out properluyHere's an example - but instead of ref cursors I've used DBMS_SQL cursors. Both are "+global+" cursors - but with DBMS_SQL cursor we can see the value of the cursor handle. In other words we can "print" the value of the cursor variable, which is what we cannot do with a ref cursor. This enables one to read and understand the sample code better as we can physically see the value of that cursor pointer/handle om the example.
The following 2 PL/SQL code units are defined:
-- // Creates a "global" cursor and returns the cursor handle (as a number for us)
create or replace function CreateCursor( sqlStatement varchar2 ) return number is
        c       number;
begin
        c := DBMS_SQL.open_cursor;
        DBMS_SQL.parse(
                c,
                sqlStatement,
                DBMS_SQL.native
        return( c );
end;
--// display the 1st column of a cursor, and we supply the cursor handle (number)
create or replace procedure DisplayCursor( c in out number ) is
        buffer  varchar2(4000);
        rc      number;
begin
        DBMS_SQL.define_column( c, 1, buffer, 4000 );
        DBMS_OUTPUT.put_line( '** displaying cursor '||c||' (1st column only)' );
        rc := DBMS_SQL.execute_and_fetch( c );
        loop
                DBMS_SQL.column_value( c, 1, buffer );
                DBMS_OUTPUT.put_line(  buffer );
                exit when DBMS_SQL.fetch_rows( c ) = 0;
        end loop;
        DBMS_OUTPUT.put_line( '** end of cursor display' );
        DBMS_SQL.close_cursor( c );
end;
/We can now create a cursor, get the handle and then later from another code unit (in the same session) use that cursor handle that was created. This means that the cursor existed from the time we've opened it, until we have explicitly closed it. In other words, a global cursor that exists for the duration of our session, or until we explicitly close the the cursor handle.
SQL> var c1 number
SQL> var c2 number
SQL>
SQL> --// we open a cursor
SQL> exec :c1 := CreateCursor( 'select object_name from user_objects where object_type =''TABLE'' and rownum <= 5' );
PL/SQL procedure successfully completed.
SQL> select 'Cursor '||:c1||' created.' as NOTE from dual;
NOTE
Cursor 710790198 created.
SQL> --// we now open a second cursor
SQL> exec :c2 := CreateCursor( 'select object_name from user_objects where object_type =''FUNCTION'' and rownum <= 5' );
PL/SQL procedure successfully completed.
SQL> select 'Cursor '||:c2||' created.' as NOTE from dual;
NOTE
Cursor 1228216362 created.
SQL>
SQL> --// we first display the 2nd cursor we've opened
SQL> exec DisplayCursor( :c2 );
** displaying cursor 1228216362 (1st column only)
CREATECURSOR
GETTOKEN
PLAINFOO
SPECIALFOO
TESTFUNC
** end of cursor display
PL/SQL procedure successfully completed.
SQL> --// we now display the 1st cursor we've opened
SQL> exec DisplayCursor( :c1 );
** displaying cursor 710790198 (1st column only)
EMPTAB
FOOTAB
FOOTAB_S
TESTRAW
TESTTAB
** end of cursor display
PL/SQL procedure successfully completed.
SQL> As you can see, these cursors are global. We create them using one unit of code. We use them via another unit of code. However, we cannot pass the DBMS_SQL handle (the number above) to our client session (e.g. Java, TOAD or SQL*Plus). We need to pass a ref cursor handle to such a client and not a DBMS_SQL handle. This allows our DisplayCursor() procedure we did in PL/SQL, to be written in client code like Java. Where the only difference is that this code will receive a ref cursor data type to process and not a DBMS_SQL cursor type.

Similar Messages

  • Execute store procedure( in Id, in out RefCursor), and data fetched in ref cursor should be sent out as excel sheet.

    I am trying to make a ssis package that get the data calling the store proc with two param one is ID and other is Sys_refcursor. Say Store Proc as ListName(Id int, myCur sys_refcursor), which gets the datas with the conditions inside it.
    REATE OR REPLACE PROCEDURE schemaName.LISTNAME (P_ID  IN INT, LST_NAME_REFCUR   IN OUT SYS_REFCURSOR)
    IS
    P_NAMESOURCE_ID INT;
    BEGIN
        SELECT SOURCE_ID INTO P_NAMESOURCE_ID FROM SEARCHING_TABLE ST WHERE ST.ID = P_ID;           
                   IF (P_NAMESOURCE_ID=1)
                   THEN
                      OPEN LST_SOURCE_REFCUR FOR 
                            SELECT ST.ID,
                                   ST.TRANSACTION_DATE AS TRAN_DATE,
              IF (P_NAMESOURCE_ID=1)
                   THEN 
                      OPEN LST_SOURCE_REFCUR FOR             ....     
    then i need to get the data from that refcursor and fetch those data to excel sheet to a virtual directory.
    Any help would be appreciated. I am new to SSIS. and i need to do this assignment this friday. 

    Hi 11srk,
    To fetch data from Oracle store procedure, you can use a Script Component as source to call the Oracle stored procedure by using System.Data.OracleClient OracleDataReader, and get the rows and add them to the pipeline buffer. For more information, please
    see:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/1d0b3a1b-8792-469c-b0d1-f2fbb9e9ff20/dump-oracle-ref-cursor-into-ms-sql-staging-table-using-ssis
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/fcdaa97e-8415-4c3e-8ffd-1ad45b590d57/executing-an-oracle-stored-procedure-from-ssis?forum=sqlintegrationservices
    http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracledatareader(VS.90).aspx  
    Regards,
    Mike Yin
    TechNet Community Support

  • Pen tool, Rounded ractangle and Brush cursor.

    Hi, Good Day.
    There are things that I want to say about using CS4.
    1.   Pen tool.
    In Photoshop 5.0, I found that it is faster to <stroke path> compared to the newer version of PS. In PS 5.0, I never need to exit pen tool mode whenever I wanted to select the brush sizes. The Brush size Selection 'tray' tab is always available even when I’ve exit the brush mode. Thus make the stroke works become faster, simpler and easier.
    And this is not happen in CS4. What I see is when every time I want to stroke the paths, to choose the brush size I must exit the pen tool mode ; and when I’m back the pen tool mode again, the brush option tray will gone. This slows me every time when I want to choose brush or when I want to re-correct or to re-stroke in order for looking the right brush size and style; it's really complicates me.
    So, can Adobe do something about the Brush Selection tab so it always availed like other tabs, like PS5.0 do? Which like swatches tab, color tab, etc.. So it wouldn’t go off next time when we exit the brush mode; thus saves time.
    2.   Rounded rectangle.
    Problem: I want to modify my rounded rectangle shape by adjusting the all the four rounded edges evenly without ruining the square shape. The problem is the shape is too free, the points are working individually and paths are “flabby”.
    Can someone tell me know how to lock the shape?
    It’s like what in Microsoft Word do. The rounded rectangle lines can be locked so I can adjust the edges to be rounder and rounder, whether partly or simultaneously.
    3.     Brush cursor.
    I found that the brush cursor seem to be ‘unstable’; which is that the PS will change the Normal brush cursor to the Precise brush cursor when I’m using the Text tool, and I can’t change the cursor back to Normal cursor again after exiting the text tool and I'm also not on the text layer. And sometimes this problem happens even when I’m not using the Text tool; for example when I’m doing some copy and paste job.
    The only solution is to close PS and restart my computer. What I should do?
    Thanks for your concern.

    Hi Bion_s,
    In the course of playing around in Illustrator to find a solution, I found that if you open your appearance panel (Window > Appearance), select the fly-out menu and deselect New Art has Basic Appearance.
    I found that with this option unselected, you can select your stroke width and profile and draw multiple times without it reverting to the default stroke!
    Please let me know if this works for you. I'm not sure how this might affect your workflow on other projects, but it did result in the behavior you seemed to want.
    Cheers,
    Michael

  • I don't have a normal cursor, which in my case is an arrow. instead i have what looks like three tin

    i don't have a normal cursor, which in my case is an arrow.  instead i have what looks like three tiny hands in a row.  this makes it very difficult to be accurate when cropping, or tilting.  i uninstalled and reinstalled, to no avail.  i'm using cs4 extended

    That sounds a bit like an old video driver bug that was fixed a while ago, or the Windows cursor scaling bug (which is still around) - set the scaling back to 100%.

  • Open and closed cursor

    I have some doubts/questions .
    What is the difference between open and closed cursor?
    Are library cache locks same as parse locks?
    What is the difference between latch and mutex?
    I would be grateful if experts could answer these questions.
    Regards

    Almost correct. The terminology is however nor correct.
    Simplistically:
    The SQL engine receives a SQL. It attempts a soft parse first. This means looking for an existing cursor in the Shared Pool with the same SQL. This existing cursor can be in use by other sessions. It does not matter - if that cursor is in used (opend by other sessions), or not. It may not be in use at all and simply sitting there in the cache. If such a cursor is found, it is used for that session's SQL - and that session gets a cursor handle (reference/pointer) to that existing cursor.
    If the SQL engine does not find an existing cursor to use, it needs to create a brand new cursor in the Shared Pool. This is a hard parse. Again, the session receives a cursor handle for that new cursor created.
    And that is it.
    You now need to decide how to use that cursor handle. The cursor itself is a program. You have a handle to execute that cursor program. Via its bind interface you can input data to this cursor program. Then execute it and receive (fetch) output of that cursor program.
    So the ideal is to re-use the cursor handle again and again.
    Basic example: the following is not optimal as the same cursor is opened and closed, opened and closed, for each read from the file. A lot of soft parsing results.
    while not-eof( filehandle )   // read data from a file
      read file data into var1, var2
      open cursor for 'insert into testtab values( :1, :2)'   // create a cursor
      bind cursor :1 = var, :2 = var2  // bind values to cursor (for insert)
      exec cursor // do SQL insert
      close cursor 
    end whileThis is a lot better. A single cursor is used and executed again and again:
    open cursor for 'insert into testtab values( :1, :2)'   // create a cursor
    while not-eof( filehandle )   // read data from a file
      read file data into var1, var2
      bind cursor :1 = var, :2 = var2  // bind values to cursor (for insert)
      exec cursor // do SQL insert
    end while
    close cursor  In this case a single soft/hard parse - and the client uses that cursor handle to execute that cursor (insert data) program again and again.

  • What is difference between enjoy transactions and Normal transactions

    What is difference between enjoy transactions and Normal transactions
    Ex:- ME22 & ME22N
    What is difference between these two.

    hi ,
    the transaction code with 'N' are created with help of object concept.
    In your case ME22 is obsolete one and ME22N is the tcode created with object concept.
    pls Reward helpful points
    Thanks
    Siva

  • Problem with generating xml and nested cursor (ora-600)

    I have a problem with generating xml (with dbms_xmlquery or xmlgen) and nested cursors.
    When I execute the following command, I get a ORA-600 error:
    select dbms_xmlquery.getxml('select mst_id
    , mst_source
    , cursor(select per.*
    , cursor(select ftm_fdf_number
    , ftm_value
    from t_feature_master
    where ftm_mstr_id = pers_master_id ) as features
    from t_person per
    where pers_master_id = mst_id ) as persons
    from f_master
    where mst_id = 3059435')
    from dual;
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00600: internal error code, arguments: [kokbnp2], [1731], [], [], [], [], [], []
    </ERROR>
    The problem is the second cursor (t_feature_master).
    I want to generate this:
    <master>
    <..>
    <persons>
    <..>
    <features>
    <..>
    </features>
    </persons>
    <persons>
    <..>
    <features>
    <..>
    </features>
    </persons>
    </master>
    If i execute the select-statement in sql-plus, then I get the next result.
    MST_ID MST_SOURCE PERSONS
    3059435 GG CURSOR STATEMENT : 3
    CURSOR STATEMENT : 3
    PERS_MASTER_ID PERS_TITLE PERS_INITI PERS_FIRSTNAME PERS_MIDDL PERS_LASTNAME
    3059435 W. Name
    CURSOR STATEMENT : 15
    FTM_FDF_NUMBER FTM_VALUE
    1 [email protected]
    10 ....
    I use Oracle 8.1.7.4 with Oracle XDK v9.2.0.5.0.
    Is this a bug and do somebody know a workaround?

    Very simple...Drop all type objects and nested tables and create them again. You will get no error. I'll explain the reason later.

  • Difference between Implicit and Explicit Cursors

    Hi All,
    Can you just tell me what is the difference between implicit and explicit cursor?
    Thanks,
    Padma

    Hi ,
    Implicit Cursor means ,the cursors which are defined impplicitly.Here we use curosr variables as "SQL%found,sql%not found,sql%is open.."
    but explicit cursors defined by us like if u create a cursor C1 then
    c1%found,c1% not found ,c1%open
    Thank you.

  • Implicit and explicit cursors

    i want to know when to it is recommended to use the implicit cursors (for rec in….) and when it is recommended to use explicit cursors(open cursors….)

    As Brett said, both methods require an explicit cursor definition. What is implicit in the FOR cursor loop is the opening and closing of the cursor. If you use a cursor FETCH loop, you need to code that explicitly yourself.
    My recommendation is to use the cursor FETCH loop and code those two additional OPEN CURSOR and CLOSE CURSOR statements. Reason: a cursor fetch loop allows for proper bulk processing code to be used. It does not rely on the implicit bulk fetching (of 10 rows per time) of a FOR cursor loop - which btw is only available in 10G.
    A FOR cursor loop does not scale. You cannot make the bulk fetching larger. Or smaller. You cannot do bulk updates or inserts in the loop.
    So I do not care what the experts think and say, for me the answer is clear cut. You want to write scalable and performant code? You will use a cursor fetch loop. Not a for cursor loop.

  • What is the real time use of implicit and explicit cursors in pl/sql

    what is the real time use of implicit and explicit cursors in pl/sql.............please tell me

    You can check the following link ->
    http://www.smart-soft.co.uk/Oracle/oracle-plsql-tutorial-part5.htm
    But, i've a question ->
    Are you student?
    Regards.
    Satyaki De.

  • Ref Cursor over Implicit and explicit cursors

    Hi,
    In my company when writing PL/SQL procedure, everyone uses "Ref Cursor",
    But the article below, says Implicit is best , then Explicit and finally Ref Cursor..
    [http://www.oracle-base.com/forums/viewtopic.php?f=2&t=10720]
    I am bit confused by this, can any one help me to understand this?
    Thanks

    SeshuGiri wrote:
    In my company when writing PL/SQL procedure, everyone uses "Ref Cursor",
    But the article below, says Implicit is best , then Explicit and finally Ref Cursor..
    [http://www.oracle-base.com/forums/viewtopic.php?f=2&t=10720]
    I am bit confused by this, can any one help me to understand this?There is performance and there is performance...
    To explain. There is only a single type of cursor in Oracle - that is the cursor that is parsed and compiled by the SQL engine and stored in the database's shared pool. The "+client+" is then given a handle (called a SQL Statement Handle in many APIs) that it can use to reference that cursor in the SQL engine.
    The performance of this cursor is not determined by the client. It is determined by the execution plan and how much executing that cursor cost ito server resources.
    The client can be Java, Visual Basic, .Net - or a PL/SQL program. This client language (a client of SQL), has its own structures in dealing with that cursor handle received from the SQL engine.
    It can hide it from the developer all together - so that he/she does not even see that there is a statement handle. This is what implicit cursors are in PL/SQL.
    It can allow the developer to manually define the cursor structure - this is what explicit cursors, ref cursors, and DBMS_SQL cursors are in PL/SQL.
    Each of these client cursor structures provides the programmer with a different set of features to deal with SQL cursor. Explicit cursor constructs in PL/SQL do not allow for the use of dynamic SQL. Ref cursors and DBMS_SQL cursors do. Ref cursors do not allow the programmer to determine, at run-time, the structure of the SQL projection of the cursor. DBMS_SQL cursors do.
    Only ref cursors can be created in PL/SQL and then be handed over to another client (e.g. Java/VB) for processing. Etc.
    So each of the client structures/interfaces provides you with a different feature set for SQL cursors.
    Choosing implicit cursors for example does not make the SQL cursor go faster. The SQL engine does not know and does not care, what client construct you are using to deal with the SQL cursor handle it gave you. It does not matter. It does not impact its SQL cursor performance.
    But on the client side, it can matter - as your code in dealing with that SQL cursor determines how fast your interaction with that SQL cursor is. How many context switches you make. How effectively you use and re-use the SQL (e.g. hard parsing vs soft parsing vs re-using the same cursor handle). Etc.
    Is there any single client cursor construct that is better? No.
    That is an ignorant view. The client language provides a toolbox, where each tool has a specific application. The knowledgeable developer will use the right tool for the job. The idiot developer will select one tool and use it as The Hammer to "solve" all the problems.

  • On startup Mac Pro I get a blue screen and a cursor on the upper left. The mouse cursor shows up independently. Is it likely a video card failure?

    On startup Mac Pro I get a blue screen and a cursor on the upper left. The mouse cursor shows up independently. Is it likely a video card failure?

    I managed to boot the computer and get the desktop to show. I now have a "repaired" computer. There are several problems that have cropped up. One is that I can only start up now in Safe Boot mode. Is there a way to turn it off? Also, I do not have a sound list, so I can't access anything requiring audio. Google Chrome only shows up as a white screen. Pictures that loaded before don't load in browsers, etc. Any suggestions? I figure I should reinstall Mac OS Lion for starts, maybe even do a mirror backup and reformat the drive. I think this drive has turned into scrambled eggs...what a headache!

  • What are smart mailboxes and why do i need both smart and "normal" ones?

    What are smart mailboxes and why do I need both smart and "normal" mailboxes?

    Hi Kingoftypos,
    Thanks for that clarification. So, now it appears that the ultimate purpose of a Smart Mailbox is to point to all emails that meet the criteria in a single place, so if they are spread among several mailboxes, you will be able to see them all together. Here is an article from Apple that describes it:
    A Smart Mailbox displays in one location messages that are stored in other mailboxes, so you don’t have to move messages between mailboxes. The messages displayed by a Smart Mailbox are based on criteria you define, and are automatically updated to include new messages that match your criteria. For example, you might create a Smart Mailbox that displays all messages found in all mailboxes from a specific sender.
    If you change a message in a Smart Mailbox, such as marking the message as read or unread, or moving or deleting the message, the change is reflected in the mailbox where the message is actually stored.
    So, adam, I would think that, if you had mail going to a lot of different places, and wanted to be able to see a particular set of those in a single place, you would use a smart mailbox. Maybe use the rules to direct your mail to different places to start with, but a smart mailbox to bring a set of common ones all together into a single smart mailbox?
    Maybe you have Rules move your Amazon mail to an Amazon folder and your Apple mail to an Apple folder, but then you have a Smart Mailbox that contains any mail that has the word "Receipt" in the Subject line?
    Just a thought....
    Cheers,
    GB

  • Project Materials and Normal Material as a part of Sales Order

    Dear Sir,
      Can any body tell me d scenario when I can create Project material and Normal materials in the same sales order ?
    My requirement is that I am using milestone billing. But this is applied for 1st 2 milestones only. For the rest it is delivery related billing.
    So my solution is to create project material for milestone billing and actual materials for delivery related billing. So in delivery it will pick from my project stock with 601 Q movement type.
    I cannot test this scenario in SAP due to some technical problem. Can anybody plz tell me that I can do this in Std SAP ?
    Thanks for co-operation
    Regards
    Keshav

    Dear Keshav,
    Probably you need not create two materials. Create a "Z" item category group and assign it in the material Sales org 2 tab. Under "Assign Item category Group" in SD configuration, you need to map the sales Document type, Item category group and Default item category. Have default item category as TAN and Manual item category as TAO. ( please choose the default as per your need). Once you are in the sales document, have TAN item category for the line item for which you require Delivery related billing and TAO for the line item for which you require milestone billing.( You can change the default item category ..which defaults based on your configuration). Double click and notice that now a billing plan tab appears for the item relavant for Milestone billing.
    I think you also have to configure the schedule line category so that the project stock is picked up while delivery. Please take help from your SD consultant.
    Warm regards,
    Srinivas Potluri

  • CIN pricing procedure and normal procedure linkup

    Hi gurus
    How do we link cin pricing procedure taxinn and normal pricing procedure rvaa01(for example)
    what are the confi settings....like we maintain jexp,jeap etc, in taxinn and pr00,k004,k005 in rvaa01, ver do we linkup these two pricing procedure to reflect in sales order item conditions screen....i feel this will be of gr8 help to so many SDCs.
    Good points if helpful...
    thanks in advance
    krishnamohan

    Hi gurus
    How do we link cin pricing procedure taxinn and normal pricing procedure rvaa01(for example)
    what are the confi settings....like we maintain jexp,jeap etc, in taxinn and pr00,k004,k005 in rvaa01, ver do we linkup these two pricing procedure to reflect in sales order item conditions screen....i feel this will be of gr8 help to so many SDCs.
    Good points if helpful...
    thanks in advance
    krishnamohan

Maybe you are looking for

  • How can I open a PDF file in Story without the format changing?

    I have tried to open my script that's a PDF file in Story and the format is not the same.  Could someone please tell me what I should do?

  • Problems using Camera Raw function in Bridge CS5.1

    Hey so I don't know what the heck is going on, but Camera Raw was working perfectly for me when I got this computer. It's a work computer, and all the programs were recently installed. I like using Camera Raw because of the easy basic editing and mas

  • OC4J - PROBLEM 10g ( 9.0.4 ) - exception: ORA-01002

    I have application perfectly running in the version 9ias (OC4J 9.0.3) when I migrated for 10g (OC4J 9.0.4) I obtained the following mistake stopping my application. exception: ORA-01002: fetch out of sequence Data of the application:      EJB CMP    

  • Problema - AdobeForm Basic

    Dopo aver disattivato l'opzione di rinnovo automatico per l'abbonamento Adobeform Basic ho attivato di nuovo il rinnovo automatico collegato alla carta di credito. Tuttavia quando entro nella pagina di creazione dei moduli mi visualizza l'account gra

  • Auditing Oracle Data

    Being on this board I've found what asking questions often more difficult than answering them. Most of people have problem with that and I am one of them. This one is also not easy to raise because it is wide-ranging I am looking for good examples an