Cursor i Referentni kursor

Embed Size (px)

Citation preview

  • 8/11/2019 Cursor i Referentni kursor

    1/22

    Submitted on 6-Dec-2003 12:05 UTC Tom's latest followup | Bookmark | Bottom

    Questions Resources Archives Links Popular Hot Files

    Home > Question Details

    Praveen -- Thanks for the question regarding "Difference between cursor and a ref cursor", version 8.1.6

    Last updated 11-Jan-2012 15:36

    You Asked

    Hi Tom,

    Feels good that i got a chance to ask you a question. I attended an interview fororacle pl/sql. There he asked one question as what is the difference between cursor andref cursor, and when would you appropriately use each of these. Could you please tell mehow can I effectively answer this question in short.

    Your input will be greatly appreciated.

    Thanks and regards,Praveen.

    and we said...

    technically, under the covers, at the most "basic level", they are the same.

    A "normal" plsql cursor is static in defintion.

    Ref cursors may be dynamically opened or opened based on logic.

    Declare type rc is ref cursor;

    cursor c is select * from dual;

    l_cursor rc;begin

    if ( to_char(sysdate,'dd') = 30 ) then open l_cursor for 'select * from emp'; elsif ( to_char(sysdate,'dd') = 29 ) then

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

    1 of 22 9/30/2014 11:39 AM

  • 8/11/2019 Cursor i Referentni kursor

    2/22

    open l_cursor for select * from dept; else open l_cursor for select * from dual; end if; open c;end;/

    Given that block of code -- you see perhaps the most "salient" difference -- no matterhow many times you run that block -- cursor C will always be select * from dual. The refcursor can be anything.

    Another difference is a ref cursor can be returned to a client. a plsql "cursor cursor"cannot be returned to a client.

    Another difference is a cursor can be global -- a ref cursor cannot (you cannot definethem OUTSIDE of a procedure / function)

    Another difference is a ref cursor can be passed from subroutine to subroutine -- acursor cannot be.

    Another difference is that static sql (not using a ref cursor) is much more efficientthen using ref cursors and that use of ref cursors should be limited to- returning result sets to clients- when there is NO other efficient/effective means of achieving the goal

    that is, you want to use static SQL (with implicit cursors really) first and use a refcursor only when you absolutely have to

    Then sit back and say "anything else you wanted to know about them"

    Reviews

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

    2 of 22 9/30/2014 11:39 AM

  • 8/11/2019 Cursor i Referentni kursor

    3/22

    December 6, 2003 - 7pm UTCBookmark | Bottom | Top

    Thanks December 7, 2003 - 2am UTC Bookmark | Bottom | Top

    Terrific explanation December 8, 2003 - 12am UTC Bookmark | Bottom | Top

    Tom the Great December 8, 2003 - 12pm UTC Bookmark | Bottom | Top

    Reviewer: from Pakistan

    Good Explain....

    Tom last week I saw a review on this site in which writer name with unknown language to me. Here Icode the name and title of review in my mother language "URDU-Pakistan" do you see it and mostimportant if yes, that How I configure oracle forms and reports for this.

    Thanks

    Followup December 7, 2003 - 8am UTC:

    I see escaped html entities in the title and something that looks like it might be in your languagefor the name

    so the title is like

    you set your NLS_LANG on the client for forms and reports -- contact support for total assistanceon that, i don't really work with foreign charactersets personally and don't have forms/reportsaround for testing.

    Reviewer: Praveen from India

    Thanks tom for that great answer with an example. This will be really helpful.

    Reviewer: DD from Chennai, India

    that was a great explanation. You are simply the best .. :)

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

    3 of 22 9/30/2014 11:39 AM

  • 8/11/2019 Cursor i Referentni kursor

    4/22

    Excellent explanation. December 8, 2003 - 5pm UTC Bookmark | Bottom | Top

    Absolutely understandable.... December 11, 2003 - 3am UTC Bookmark | Bottom | Top

    NLS Lang December 29, 2003 - 2pm UTC Bookmark | Bottom | Top

    December 29, 2003 - 2pm UTC Bookmark | Bottom | Top

    Can U see this December 29, 2003 - 2pm UTC Bookmark | Bottom | Top

    Reviewer: Manish Upadhyay from Madison WI

    I wanted to know the same difference and your explanation is what I needed. Thanks a lot for beingthere and help so many people.

    Reviewer: Dilip Patel from Maryland, USA

    Even though I knew before what pl/sql cursor is and what ref cursor is, your explanation reallycompletes my understanding on how they differentiate.

    Thanks Much.

    Reviewer: Biswadip Seth from India

    thanks,,,your respose of this question is absolutely easy to understandable.even any begginer's to theoracle can make out this article...thanks a lot

    Reviewer: Arabic Masood Sultan Ali Betheri from KSA

    You can use the NLS_LANG environment variable to customise the forms and reports/sql plus on yourplatform. I have done it in Arabic. It really works!

    Reviewer: A reader

    Reviewer: A reader

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

    4 of 22 9/30/2014 11:39 AM

    A k T "Diff b t d f " htt // kt l / l / kt /f? 100 11 0 P11 QUESTION ID 14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    5/22

    December 29, 2003 - 3pm UTC Bookmark | Bottom | Top

    $%^&* does not follow December 29, 2003 - 5pm UTC Bookmark | Bottom | Top

    Simply Great January 25, 2004 - 6pm UTC Bookmark | Bottom | Top

    most useful March 17, 2004 - 12am UTC Bookmark | Bottom | Top

    b MV xV CW

    zW U W x c MZ b. dVJVGJ x. EV JJ b dxW MZ dBZ

    Can you interpret the above?

    Followup December 29, 2003 - 2pm UTC:

    nope, just a bunch of characters -- none of them ascii.

    Reviewer: A reader

    Is that Russian ??

    Reviewer: Harrison from Haymarket, "Like Detroit, without the glitter" VA, USA

    I learned at least two things, a better grasp of when to use reference cursors, and how to pushunrelated questions onto the stack.

    Reviewer: Vijay Dwivedi from Muscat (Sultanate of Oman)

    It is really great to see these differences, but why these were not explained in Oracle Books sosimple..

    Reviewer: vishram from india

    most useful

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

    5 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs " https://asktom oracle com/pls/asktom/f?p=100:11:0::::P11 QUESTION ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    6/22

    Excellent March 22, 2004 - 12am UTC Bookmark | Bottom | Top

    March 24, 2004 - 1am UTC Bookmark | Bottom | Top

    Thank You Very Much April 29, 2004 - 10am UTC Bookmark | Bottom | Top

    Clarity at its best June 10, 2004 - 4am UTC Bookmark | Bottom | Top

    Arabic Nls Lang November 30, 2004 - 10am UTC Bookmark | Bottom | Top

    Reviewer: Jayasri from India

    That's indeed a great explanation Tom!

    Reviewer: Devesh joshi from India

    An Excellent Example

    Reviewer: Sugandha from California, USA

    I have a PL/SQL developer job interview today and though I had an idea about the diff in REFcursors and normal cursors, I was not sure how to put it in such simple words. Thanks for helpingme out

    Reviewer: Apratim Shaw from INDIA

    Clear and comprehensive.No wonder I love your book - Expert One-on-One

    Reviewer: Amr Mohamed Elabbasy from EgyptI ask about how to change my forms and reports to read in arabic plz send 2 me thx

    Followup November 30, 2004 - 11am UTC:

    nothing to do with "cursors and ref cursors" as far as I can tell.

    Ask Tom Difference between cursor and a ref curs... https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

    6 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs " https://asktom oracle com/pls/asktom/f?p=100:11:0::::P11 QUESTION ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    7/22

    January 13, 2005 - 11am UTC Bookmark | Bottom | Top

    Ref Cursor Explanation February 20, 2005 - 3pm UTC Bookmark | Bottom | Top

    April 27, 2005 - 8am UTC Bookmark | Bottom | Top

    Excellent May 11, 2005 - 6am UTC Bookmark | Bottom | Top

    May 13, 2005 - 2am UTC Bookmark | Bottom | Top

    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96529/toc.htm

    is the document you want to read and assuming

    a) your database has data in arabicb) your database character set actually supports that datac) you have the proper fonts installed on your clientd) they have their NLS_LANG set properly (you'll read about that)

    it should just work.

    Reviewer: PKaur from London

    This answer gave me the clear difference between cursors and ref cursors I was looking for.Thankyou very much Tom.

    Reviewer: Simon from Gloucester, England, UK

    Excellent

    Reviewer: R.Krit from Italy

    you are the best Tom :-)

    Reviewer: Gauri from India

    I have no words to describe how simply the concept was explained.I was very confused till now.Now Ihave a fair idea of what REF_CURSORS are.Thanks Tom,Absoloutely wonderful!!

    Reviewer: Bhupinder Singh from Mumbai, India

    Ask Tom Difference between cursor and a ref curs... https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

    7 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11 QUESTION ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    8/22

    Nice difference May 14, 2005 - 4am UTC Bookmark | Bottom | Top

    March 28, 2006 - 12am UTC Bookmark | Bottom | Top

    PL/SQL Cursor and Ref Cursor April 5, 2006 - 2pm UTC Bookmark | Bottom | Top

    I got correct answer after so many years

    Reviewer: Gaurav C. Pandey from India

    Now i am able to distingiush between Ref. cursor and cursor.

    Reviewer: kanchan santani from MUMBAI,INDIA

    Absolutely Wonderful!!Really happy to get such concepts cleared.thanks a lot...Tom

    Reviewer: Ram from Harrisburg, PA

    Hi Tom,Most useful, but I need one clarificaiton though. As I was going through the article on differencesbetween PL/SQL Cursor and Ref cursor, Ref cursor can be used(in addition to others) to return recordset to Client.

    I am on a Web based project with N-Tier architecture,I simply write a stored proc with Select....and call the stored proc from COM+ layer and returndata to clientas recordset. ASP vbscript will loop through recordset for display.

    In this case there is no need to use Ref Cursor to pass data to client. Please comment.

    thanksRam

    Followup April 6, 2006 - 9am UTC:and how will you return a "record set" from a plsql stored procedure to vb?

    Ask Tom Difference between cursor and a ref curs... https://asktom.oracle.com/pls/asktom/f?p 100:11:0::::P11_QUESTION_ID:14188501024541

    8 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    9/22

    April 6, 2006 - 9am UTC Bookmark | Bottom | Top

    You will be using a ref cursor to return a result set to vb.

    Reviewer: Ram from Harrisburg, PA

    Hi Tom,Sorry, I forgot to mention DB. The DB for this project is SQL Server.

    --- Proccreate procedure GET_dept_data()begin Select * from deptend

    --- Inside COM+Public Function GetData() As ADODB.Recordset

    Set GetData = Execute GET_dept_data using ADOEnd--- Inside ASpInstantiate DLL andSet recset = DLL.GetData()---

    This works in SQLServer.

    I was wondering if something like this is possible in Oracle WITHOUT using RefCursor

    ThanksRegards

    Followup April 7, 2006 - 3pm UTC:

    In Oracle - the ref cursor is the way to do it.

    create procedure get_dept_data( p_cursor in out sys_refcursor )asbegin open p_cursor for select * from dept;end;

    p p p _Q _

    9 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    10/22

    Clarified April 10, 2006 - 9am UTC Bookmark | Bottom | Top

    Super May 2, 2006 - 10am UTC Bookmark | Bottom | Top

    Clear simple explanation May 18, 2006 - 7am UTC Bookmark | Bottom | Top

    and here are examples of binding to it in various languages/apis

    http://asktom.oracle.com/~tkyte/ResultSets/index.html

    and please - begging you to remember "sqlserver isn't oracle, oracle isn't sqlserver, A is not B, Bis not A"

    If we were identical in every aspect, it would be useless to have more than one.

    Reviewer: Ram from Harrisburg, PA

    Hi Tom,Understood Sir..I am getting ready for myself,since there is a possibility to migrate to Oracle.

    ThanksRegards,Ram

    Reviewer: Ram from Harrisburg, Pa

    Hi Tom,Super explanation. Now I know exactly what is Ref Cursor& Cursor. I also thank Praveen who started this.

    Thanks

    Reviewer: kannan from NZ

    Thanks for the simple and clear explanation of the differences between Cursors and Ref Cursors. Ireally enjoyed it.

    10 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    11/22

    practical use of ref cursor within pl/sql May 25, 2006 - 11am UTC Bookmark | Bottom | Top

    Cursors and Bulk collect May 25, 2006 - 5pm UTC Bookmark | Bottom | Top

    Reviewer: shipra from Radaur, Shipra

    I am clear with ref cursor no, that was great. But i am always in doubt that what can be thepractical example of using ref cursor within pl/sql. I understand the use of it when i am calling

    any function through front end(VB etc)...But in my project, i am calling functions through UNIXonly. I will apprecite if you can tell me a scenerio where I am bound to use REF CURSOR.

    Thanks in advance.

    Followup May 25, 2006 - 1pm UTC:

    dynamic sql

    open cursor for 'select ......';

    Reviewer: info

    Tom, How does Cursors and bulk collect differ ?

    Cursor c1 is select * from emp;--begin select * bulk collect into [array] from emp;

    what happens after doing a bulk collect, does it store in memory? then we have cursor for that .Which one is better and why?Hope my question makes sense..

    I am just trying to understand the fundamental concepts[:-)] after working in Oracle for many years..

    Thanks,

    11 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    12/22

    Diff between cursor and Ref cursor May 26, 2006 - 5am UTC Bookmark | Bottom | Top

    Cursors and Bulk collect May 27, 2006 - 7pm UTC Bookmark | Bottom | Top

    Explanation of difference between cursor and ref cursor is too good. December 7, 2006 - 1am UTCBookmark | Bottom | Top

    Followup May 25, 2006 - 6pm UTC:

    do you have access to "Effective Oracle by Design" - a book I wrote.

    Reviewer: Chandra Bhushan from India

    This difference is really very helpful for developers.It gives the most of clear pictures of Pl/Sql cursor and Ref Cursor.

    Thanks,Chandra

    Reviewer: info

    Tom, Unfortunately, I do not have access to that book right away.

    But I promise I'm going to buy after these holidays ;-)

    Thanks,

    Followup May 27, 2006 - 9pm UTC:

    A cursor and bulk collect do not "differ"

    In order to bulk collect - you need a cursor.bulk collecting is "array fetching", it is a more efficient way to process a cursors result setwhen the cursor returns more than a handful of rows.

    Reviewer: Archana from India

    Hi Tom,

    12 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    13/22

    A Reader December 11, 2006 - 1pm UTC Bookmark | Bottom | Top

    Can you explain this in detail? December 12, 2006 - 10am UTC Bookmark | Bottom | Top

    I am a new visistor to this site. Thanks. I was really looking for the difference between cursorand ref cursor.

    Thanks & Regards,Archana .

    Reviewer: Hari from pune, india

    hi tom i need a clarification about ref cursor, i saw one example given by u, i understood thatone. but first what is a ref cursor and what is the use? give me full clarification with goodexamples.

    Followup December 11, 2006 - 2pm UTC:

    just read the original example

    Reviewer: A reader Tom, You have given differences in original answer above , but can you explain more on this point?

    Another difference is a cursor can be global -- a ref cursor cannot (you cannotdefine them OUTSIDE of a procedure / function)

    I thought I understood it..but again..not[An Example would be much better for me to understand].

    Thx.

    Followup December 12, 2006 - 10pm UTC:

    try to define one outside of a procedure, as a global in a package body for example.

    13 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    14/22

    ops$tkyte%ORA9IR2> create or replace package my_pkg 2 as 3 procedure p; 4 end; 5 /

    Package created.

    ops$tkyte%ORA9IR2>ops$tkyte%ORA9IR2> create or replace package body my_pkg 2 as 3 4 procedure p 5 is 6 x sys_refcursor; 7 begin 8 null; 9 end; 10 11 end; 12 /

    Package body created.

    ops$tkyte%ORA9IR2> create or replace package body my_pkg 2 as 3 x sys_refcursor; 4 5 procedure p 6 is 7 begin 8 null; 9 end; 10 11 end; 12 /

    Warning: Package Body created with compilation errors.

    ops$tkyte%ORA9IR2> show errorsErrors for PACKAGE BODY MY_PKG:

    LINE/COL ERROR-------- -----------------------------------------------------------------3/4 PLS-00994: Cursor Variables cannot be declared as part of a

    package3/4 PL/SQL: Item ignored

    14 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    15/22

    December 20, 2006 - 10pm UTC Bookmark | Bottom | Top

    Please explain "Cursor can be Global" December 24, 2006 - 6am UTC Bookmark | Bottom | Top

    Reviewer: A Reader from NJ USA

    Hi Tom,

    my understanding is sys_refcursors are always using dynamic SQL, so is there a difference(performance etc) between get_dept_data1 & get_dept_data2

    create procedure get_dept_data1( p_dept_no in varchar2, p_cursor in out sys_refcursor )asbegin open p_cursor for select * from dept where dept_no = p_dept_no;end;

    create procedure get_dept_data2( p_dept_no in number, p_cursor in out sys_refcursor )asbegin open p_cursor for 'select * from dept where dept_no = ''' || tO_char(p_dept_no || '''';end;

    Followup December 22, 2006 - 5am UTC:

    your understanding is "wrong"

    sort of.

    there is ONLY dynamic sql - all sql is dynamic. Languages like PL/SQL and C (with pro*c) and Java

    with SQL/J can provide this thing called "static sql" which really means 'known at program compiletime'. But at the end of the day - it is processed not any differently by Oracle than 'dynamicsql' is - because it really is dynamic sql under the covers.

    That said - your get_dept_data2 should NEVER SEE THE LIGHT OF DAY

    a) it isn't using binds, bad bad badb) it has no need to not us static sql, you lose all of the compile time benefitsc) you are putting quotes around a number, bad bad bad

    15 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    16/22

    Great explanation January 2, 2007 - 10am UTC Bookmark | Bottom | Top

    Good Answer January 2, 2007 - 10am UTC Bookmark | Bottom | Top

    Reviewer: Gowtham Sen from INDIA

    Its very good explanation. It helps me a lot in understanding cursors. I have one doubt. "Another difference is a cursor can be global -- but aref curson cannot" Please explain it. I didn't get it.

    Thanks and regardsGowtham sen.

    Followup December 24, 2006 - 9am UTC:

    ops$tkyte%ORA10GR2> create or replace package my_pkg 2 as 3 cursor global_cursor is select * from dual; 4 end; 5 /

    Package created.

    ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> create or replace package my_pkg 2 as 3 global_cursor sys_refcursor; 4 end; 5 /

    Warning: Package created with compilation errors.

    ops$tkyte%ORA10GR2> show errErrors for PACKAGE MY_PKG:

    LINE/COL ERROR-------- -----------------------------------------------------------------3/16 PL/SQL: Declaration ignored3/16 PLS-00994: Cursor Variables cannot be declared as part of a package

    Reviewer: A reader

    I got ur point...

    16 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    17/22

    Great answer !!! January 8, 2007 - 12am UTC Bookmark | Bottom | Top

    Very much clear January 16, 2007 - 6am UTC Bookmark | Bottom | Top

    Wouldn't it be neat if .... April 26, 2007 - 11am UTC Bookmark | Bottom | Top

    August 7, 2007 - 3am UTC Bookmark | Bottom | Top

    Reviewer: Mayank Jain from India

    It is really understood

    Reviewer: Subhas from IndiaHi Tom,

    its awesome :)-Your answer cleared all my doubts.

    Reviewer: Poorni from India

    Hi Tom,Iam referring your articles from quite a long time.you are simply great

    Reviewer: Arun Mathur from Marietta,GA

    Create table as from ;

    would also accept reference cursors ie:

    create table as select * from ;

    I'm testing a database function which I wrote that scales better than the existing one in production; however, I want to:

    1) Place resultsets from both functions to a table2) Fire up SQL*Plus and compare the resultsets.

    No biggie. I'll just fetch/insert them out during the database function.

    Regards,Arun

    17 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    18/22

    Difference between cursor and a ref cursor November 14, 2007 - 12pm UTC Bookmark | Bottom | Top

    Simple & Neat Explanation February 5, 2011 - 12am UTC Bookmark | Bottom | Top

    Excellent May 8, 2011 - 5am UTC Bookmark | Bottom | Top

    Thoroughly Explained. January 6, 2012 - 10am UTC Bookmark | Bottom | Top

    January 11, 2012 - 3pm UTC Bookmark | Bottom | Top

    Reviewer: shilpesh from india

    You are simply superb TOM!!!!

    Reviewer: Badri S from USA

    Its a very useful and nice explanation. really useful set of points !!

    Thanks a ton Tom

    Reviewer: A reader

    Thanks a ton, Its user friendly explanation.

    Reviewer: Guna from INDIA

    It was ex tra ordinary ... your examples are very simple and understandable ..

    Reviewer: Priya from Ashburn, VA USA

    I appreciate the knowledge/understanding that you share with the readers. This explanation hashelped me in understanding the concept to a great extent.

    Followup January 10, 2012 - 10pm UTC:

    Reviewer: mfz from 08831How can I use a refcursor to spit the result set from a with clause.

    18 of 22 9/30/2014 11:39 AM

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    19/22

    SQL*Plus: Release 11.2.0.3.0 Production on Wed Jan 11 15:54:45 2012

    Copyright (c) 1982, 2011, Oracle. All rights reserved.

    Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options

    SQL> WITH deptList AS 2 (SELECT SUBSTR (txt, instr (txt, ',', 1, level ) + 1, Instr (Txt, ',', 1, Level+1) - Instr(Txt, ',', 1, Level) -1 ) AS deptcode 3 FROM 4 (SELECT ',' ||('003,050') ||',' txt FROM dual 5 ) 6 CONNECT BY level variable x refcursor;SQL> open x for WITH deptList ASSP2-0734: unknown command beginning "open x for..." - rest of line ignored.SQL> (SELECT SUBSTR (txt, instr (txt, ',', 1, level ) + 1, Instr (Txt, ',', 1, Level+1) - Instr(Txt, ',', 1, Level) -1 ) AS deptcode 2 FROM 3 (SELECT ',' ||('003,050') ||',' txt FROM dual 4 ) 5 CONNECT BY level

  • 8/11/2019 Cursor i Referentni kursor

    20/22

    Ask Tom "Difference between cursor and a ref curs..." https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14188501024541

  • 8/11/2019 Cursor i Referentni kursor

    21/22

    Excellent July 25, 2013 - 10am UTC Bookmark | Bottom | Top

    September 21, 2013 - 12am UTC Bookmark | Bottom | Top

    October 21, 2013 - 5am UTC Bookmark | Bottom | Top

    reader December 3, 2013 - 6am UTC Bookmark | Bottom | Top

    Perfect April 1, 2014 - 6pm UTC Bookmark | Bottom | Top

    Reviewer: sagayakapil from SG

    That was really great. I feel good that at least i knew the difference. Keep up the good work.Thanks.

    Reviewer: Sureshkumar from Chennai, India

    Wonderful! simple examples which are given huge ideas... Great!...

    Reviewer: Giridhar from India

    Nice explanation. Its really useful

    Reviewer: Venky from Singapore

    Try this Way

    WITH deptList AS (SELECT regexp_substr(txt,',?\d+,?',1,level) AS deptcode FROM (SELECT '003,050' txt FROM dual) CONNECT BY level

  • 8/11/2019 Cursor i Referentni kursor

    22/22

    But why do we use a ref cursor exactly? August 12, 2014 - 12pm UTC Bookmark | Bottom | Top

    Hi,

    I always had this doubt about cursor and ref cursor. Your answer was very clear. Thanks a lot.

    Reviewer: Prateek Dave from Kolkata, India

    Hello Tom,Just to start..I had an interview around a month ago and the interviewer asked me this question. Imentioned the uses you mentioned in this review (for dynamic sql, to pass it between subroutines,to pass it to clients). But he kept me asking "Its OK..but why do we actually use the ref cursor".Still I didnt get what he was looking for (I got the job though). A question from my side. Is therea difference in which a normal cursor and a ref cursor access the memory structures (SQL AREA).

    Write a Review

    All information and materials provided here are provided "as-is"; Oracle disclaims all express and implied warranties, including, the implied warranties of merchantability or fitnessfor a particular use. Oracle shall not be liable for any damages, including, direct, indirect, incidental, special or consequential damages for loss of profits, revenue, data or data

    use, incurred by you or any third party in connection with the use of this information or these materials.

    About Oracle | Legal Notices and Terms of Use | Privacy Statement

    22 of 22 9/30/2014 11:39 AM