Are Explicit Cursors better than Select Statement

Hi Gurus,
I came across this opinion that explicit cursors are better (even if the query returns a single row) instead of a single row SELECT statement within the code in terms of performance.
Is that true??? Pls elaborate in either case.
Can i hear it from Sri/Andrew ???
Thanks for ur time...
Peyush

no, it is just the opposite
see
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1205168148688
for a complete explanation why
greetings
Freek
Hi Gurus,
I came across this opinion that explicit cursors are better (even if the query returns a single row) instead of a single row SELECT statement within the code in terms of performance.
Is that true??? Pls elaborate in either case.
Can i hear it from Sri/Andrew ???
Thanks for ur time...
Peyush

Similar Messages

  • Use of cursors insted of select statements

    could any one please explain what is the advantage of using cursors instead of simple select statements
    thanks
    siby

    A benefit to using an explicit cursor rather than a select statement, is for the NO_DATA_FOUND exception. Its kind of like a free IF statment. IF no data is found, then stop.
    if you write a select statement, and no data is returned, you SHOULD code for the NO_DATA_FOUND exception. Often people say, "i'll ALWAYS get a row returned". but you should always cover your code "just in case". so you must code an exception...
    declare
    v_var varchar2(1);
    procedure do_something(p_parm varchar2) is
    begin
    null;
    end do_something;
    procedure log_error is
    begin
    null;
    end log_error;
    begin <<main>>
    do_something('x');
    begin <<selectblock>>
    select dummy
    into v_var
    from dual
    where dummy = 'a';
    do_something(v_var);
    exception
    when no_data_found then
    log_error;
    end selectblock;
    do_something (v_var||'abc');
    end main;
    if you use an explicit cursor instead, you don't need to code for the NO_DATA_FOUND. If an explicit cursor opens and finds no rows, there are simply no rows. of course, you don't need a loop if you expect only 1 row returned under normal circumstances.
    BTW, don' forget that SQL%ROWCOUNT and your_cursor%ROWCOUNT are not initialized. There is a null, until a row is successfully fetched. therefore if no rows are returned at all, %ROWCOUNT is NULL.
    declare
    v_var varchar2(1);
    cursor my_cur is
    select dummy
    from dual
    where dummy = 'a';
    procedure do_something(p_parm varchar2) is
    begin
    null;
    end do_something;
    procedure log_error is
    begin
    null;
    end log_error;
    begin << main>>
    for cur_rec in my_cur loop
    dbms_output.put_line('inside');
    begin <<loop_block>>
    if nvl(my_cur%rowcount,0) > 1 then
    do_something(cur_rec.dummy);
    else
    log_error;
    end if;
    end loop_block;
    end loop;
    end main;
    /

  • Is it better to use bapi_salesorder_getlist than select statements?

    hi experts,
    in terms of performance, which is better in getting a list of salesorders is it better bapi_salesorder_getlist or select statements?
    for bapi_salesorder_getlist, i will not get all of the fields so i would still use select.
    Message was edited by:
            maui bayog

    Hi,
    If ur requiremetn is specific and can be solved using bapi_salesorder_getlist then only use it, otherwise, use select stament which is more useful for reports as it gives o/p as required and not a predefined limited output.  Now u may get sufficient fields but , in future if requirement will change then for small change u may be in problem.
    Bapis are very userful for specifc and limited tasks.
    Jogdand M B

  • Why are two queries better than one

    I'm trying to help out our developers who are struggling with the performance of a very simple select statmenent that for some reason is exhibiting some very inexplicable results.
    I'll show the SQL as a single statement first.....
    select * from transaction1 t where t.hid in (select distinct h.hid from history1 h,filter1 f where h.fid = f.fid and f.match='value');
    transaction 1 has 250k records, history1 has about 100k as does filter1. We know generally the subselect will only return a total of half a dozen or less records (only 1 in our testing here).
    Running the above query takes around 7 seconds.
    Changing this to a with clause.....
    WITH a as (select distinct h.hid from history1 h,filter1 f where h.fid = f.fid and f.match='value') select * from transaction1 t where t,hid in (select a.hid from a);
    and the runtime drops to 3 seconds. But then re-running the first statement again also now takes 3 seconds (so I guess there's some caching going on there).
    Now what really puzzles is if we split this into two queries.....
    select distinct h.hid from history1 h,filter1 f where h.fid = f.fid and f.match='value';
    This takes .1 of a second,
    select * from transaction1 t where t.hid in (12345);
    And this takes .1 of a second.
    So why when run seperately are they so fast, yet combined they take so long. I'm a bit baffled by this. We've rewritten the same SQL in half a dozen different ways with the same result and also done the same thing with other tables as well. Is it an optimisation issue?

    Appologies for not following protocol, my first time posting on here.
    Oracle 10g clustered.
    We have limited access as it's a customers server, but the explain plan comes back as....
    PLAN_TABLE_OUTPUT
    Plan hash value: 898894568
    | Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)|Time     |
    PLAN_TABLE_OUTPUT
    |   0 | SELECT STATEMENT     |                   | 49553 |    37M|  7075   (2)|00:01:25 |
    |*  1 |  HASH JOIN RIGHT SEMI|                   | 49553 |    37M|  7075   (2)|00:01:25 |
    |   2 |   VIEW               | VW_NSO_1          | 26131 |   331K|   476   (4)|00:00:06 |
    |*  3 |    HASH JOIN         |                   | 26131 |   791K|   476   (4)|00:00:06 |
    PLAN_TABLE_OUTPUT
    |*  4 |     TABLE ACCESS FULL| FILTER1           | 26131 |   484K|   246   (4)|00:00:03 |
    |   5 |     TABLE ACCESS FULL| HISTORY1          |   104K|  1225K|   227   (3)|00:00:03 |
    |   6 |   TABLE ACCESS FULL  | TRANSACTION1      |   199K|   150M|  6593   (1)|00:01:20 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - access("T"."TID"="$nso_col_1")
       3 - access("H"."HID"="F"."ID")
       4 - filter("F"."MATCH"='value')
    20 rows selectedI'll admit, I'm not completely clear on what I'm reading here, other than the fact there are some big differences in the timing values
    We don't have privaleges to run trace, so I'm a bit stuffed there as I'm on the clients site, however I will get my developers to try this on our local server.
    Edited by: user1410957 on 15-Sep-2009 06:14

  • Are Apple routers better than others?

    I have wi-fi at my home and I have problems with AirPlay as it sometimes skips.
    I'm thinking of buying Time Capsule and I want to know if it's powerfull enough to work in a normal size house and will it solve AirPlay problem?
    Is wi-fi on Time Capsule better than on Motorola VIP1003 router?

    The broadcast power of all routers is limited by law. Every manufacturer is running their products at 100%, so there will be very little difference between routers of different manufacturers.
    If you have having difficulty now, replacing your router with a Time Capsule will likely not solve your problems.
    Instead, you will probably need to look for "extending" or "repeating" devices to provide a stronger signal throughout your house....whether you elect to add the Time Capsule or not.

  • Are 2 drives better than 1

    I am not planning on doing any raid. My Question:
    If you have 2 drives: 1 for the boot and the other for data:
    (250g each). Would that setup be better than one 500g drive in terms of speed etc?
    Just looking for opinions?

    Beside of that purpose on the previous post, I prefered split that HD into two for back up and ease of restoring data and system purpose.
    So the next time you want to reinstall the OS and all programs I could concentrate on the Os system drive without having to much worry about data which is stored on other drive or if I want to back up data, just concentrate on data drive without worrying about accidently deleted system or part of program files.
    Good Luck.

  • Are wireless routers better than non-wireless ones?

    Hey all,
    I've come to this forum, because the last time I had a problem with my computer, this venue definitely gave me the best answers and I learned quite a bit of information.
    Anyhow, I have recently moved and want to connect my computer to the optimum online (the long island version of road runner) modem. However, I need a router, because cablevision is too cheap to provide one (even though Verizon does for their DSL service, and it's about 60% of the cost of time warner, but that's not why I'm here...haha). I actually have a few questions regarding this issue.
    1. Is a wireless router going to give me as much as speed as a non-wireless one? (Keep in mind, I live way out east on the island, where it's pretty rural)
    2. I'm concerned about virus protection. My dad's PC is completely infected with viruses. Even though he'll be purchasing a new one in the next few months, I'm concerned that they may infiltrate my computer. I have Virex and I've had no problems whatsoever with viruses (or is it virii), but I want to continue with that clean record. I saw there are some modems with firewall built in. Does that make a difference?
    3. Verizon let me keep their DSL modem with inputs for 4 ethernet cables (the built-in router I suppose). Is there any way I can use this as a router for the cable service? I apologize for this question, but if I can find a use for this modem, I'd like to (and DSL is not available in this area).
    Thanks a lot. Happy New Year!
    ~Jeremy

    Jeremy, First welcome to the discussions,
    Wireless technology is just a few mbs slower than a wired connection, for the most part you won't notice it.
    Cabble is different than DSL. With cable you will get better more consistant speeds than you will with DSL.
    Normally DSL is furnished through phone lines and the farther you are from the ISP's Servers the slower your connection is. This is not the case with Cable.
    You are correct about Viruses. Mac is not to date affected by viruses Trojans and Malware. It is a good idea if for no other reason than peace of mind to have Virex or
    http://www.clamxav.com/
    All ISp's have firewalls on there servers, as well as any Router you buy will have a Firewall that is normally configured by typing in 192.168.1.1 in your Browser this will open the Routers Utility settings. This information is with any Routers Paperwork.
    Mac OSX has one of the best firewalls you can also set up.
    Normally almost all Viruses are sent through e-mail while they won't affect the UNIX operating system when you get an e-mail with a virus you can pass it on to another windows user who can be infected.
    If you have the adapter that plugs in to the socket that accepts the Cable in and the Cat5 or Cat6 out then yes you can use it, you will need the Ip Address that your service provides. If your serviceuses Cat 5 or 6 Eternet Cable the technology is the same worldwide. It really depends on what your cable service has furnished you with.
    You should be able to run an ethernet cable from your Internet Service Providers Modem ( Instead of plugging it in to your computer) Plug it into the Uplink port of the Verizon Router and try it. Like I said you may have to get into the Utility and set the Ip for you to do away with the other one, you should only need one.
    It would however be the hot set up if you can use the Modem Router Combined.
    There is also a good chance if they haven't hooked you up yet show the tech that comes to hook you up the Modem Router you have and if he can he will probably use it if you talk real nice.
    Remember for the most part a Modem is a Modem, and a Router is a Router. Some have a few different features but the technology is the same and works under the same principles.
    This should help. Don

  • Are ipad maps better than a satnav when travelling in europe?

    I'll be travelling in England, France and Ireland later on in the year and am wondering whether I can use my ipad for maps or if it is cheaper to buy a satnav.  I have heard that data charges are high.

    Satellite navigation systems are dedicated to their tasks without the need for external data feeds (except for the map updates you will perform probably only before you leave).
    Also, iPads displayed for all the world to see seems a juicer theft target than a tiny unglamorous GPS box.
    My humble opinion.

  • Are any aps better than lock & load X for shaky cam

    I shot a lot of vacation footage and a fair amount of it is pretty shaky.  I've tried the free download for Lock & Load X from Core Melt and it seems to work for some shots but not all.  Does anyone know of any other apps out there that are better for shaky camera footage, or is there some aspect of Lock & Load that if applied will make it work better?  Thanks for any help--

    Also…many people swear by Warp Stabilizer in After Effects. There is a 30 day trial if you would like to evaluate it.
    There is also a pretty good stabilizer in Motion ($49), which I think is the same engine that FCP X (meaning the new FCP, not Final Cut Express) uses but with some more controls.
    Russ

  • Why are Ipod Apps better than Iphone Apps?

    There are some really nice apps available to the ipod touch that aren't available to the Iphone. Go search Ipod apps in the Itunes store and you will see what I am talking about. How come the same apps aren't available for both devices?

    oops, they are not on the touch they are for the nano, and reg ipod. Still I am sure there is a way to develope them for the iphone.

  • Are MSI drivers better than NVidia drivers?

      I wasn't sure, i use nvidia and dont have many system crashes (once a week at max). But I wondered if MSI ones were good? I have an AGP 6600GT.

    ratkid132,
    Go with the nVidia ForceWare Drivers every time, and that goes for any company that makes GeForce or Radeon Hardware, always go to either nVidia or ATI for Drivers.
    Take Care,
    Richard

  • Using Cursor in Select statements? How to do this?

    I am getting an error whilt passing a cursor to a select clause:
    SELECT dbms_xmlquery.getXML('select deptno, dname, '||
    'cursor(select empno, ename, sal from emp e where e.deptno = d.deptno) employees '||
    'from dept d where d.deptno in (10, 20)')
    FROM dual;
    DBMS_XMLQUERY.GETXML('SELECTDEPTNO'||'CURSORIS(SELECTEMPNOFROMEMPEWHEREE.DEPT=D.
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00923
    : FROM keyword not found where expected
    </ERROR
    THIS IS DUE TO THE CURSOR AND ITS FROM STATEMENT?
    CAN ANY ONE PLEASE GUIDE AS TO HOW TO USE CURSORS IN A SELECT STATEMENT PLEASE?

    Another duplicate thread. See my response Select CLAUSE error using CURSORS & XSU.Please SEE..
    Cheers, APC

  • How to pass values in select statement as a parameter?

    Hi,
    Very simple query, how do I pass the values that i get in the cursor to a select statement. If table1 values are 1,2,3,4 etc , each time the cursor goes through , I will get one value in the variable - Offer
    So I want to pass that value to the select statement.. how do i do it?
    the one below does not work.
    drop table L1;
    create table L1
    (col1 varchar(300) null) ;
    insert into L1 (col1)
    select filter_name from table1 ;
    SET SERVEROUTPUT ON;
    DECLARE
    offer table1.col1%TYPE;
    factor INTEGER := 0;
    CURSOR c1 IS
    SELECT col1 FROM table1;
    BEGIN
    OPEN c1; -- PL/SQL evaluates factor
    LOOP
    FETCH c1 INTO offer;
    EXIT WHEN c1%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(offer);
    select * from table1 f where f.filter_name =:offer ;
    factor := factor + 1;
    DBMS_OUTPUT.PUT_LINE(factor);
    END LOOP;
    CLOSE c1;
    END;

    Hi User,
    You are looking somethuing like this, as passing the values to the Cursor as a Paramter.
    DECLARE
       CURSOR CURR (V_DEPT IN NUMBER)    --- Cursor Declaration which accepts the deptno as parameter.
       IS
          SELECT *
            FROM EMP
           WHERE DEPTNO = V_DEPT;    --- The, Input V_DEPT is passed here.
       L_EMP   EMP%ROWTYPE;
    BEGIN
       OPEN CURR (30);       -- Opening the Cursor to Process the Value for Department Number 30 and Processing it with a Loop below.
       DBMS_OUTPUT.PUT_LINE ('Employee Details for Deptno:30');
       LOOP
          FETCH CURR INTO L_EMP;
          EXIT WHEN CURR%NOTFOUND;
          DBMS_OUTPUT.PUT ('EMPNO: ' || L_EMP.EMPNO || ' is ');
          DBMS_OUTPUT.PUT_LINE (L_EMP.ENAME);
       END LOOP;
       CLOSE CURR;
       DBMS_OUTPUT.PUT_LINE ('Employee Details for Deptno:20'); -- Opening the Cursor to Process the Value for Department Number 20
       OPEN CURR (20);
       LOOP
          FETCH CURR INTO L_EMP;
          EXIT WHEN CURR%NOTFOUND;
          DBMS_OUTPUT.PUT ('EMPNO: ' || L_EMP.EMPNO || ' is ');
          DBMS_OUTPUT.PUT_LINE (L_EMP.ENAME);
       END LOOP;
       CLOSE CURR;
    END;Thanks,
    Shankar

  • Passing value as a parameter in select statement

    Hi,
    Very simple query, how do I pass the values that i get in the cursor to a select statement. If table1 values are 1,2,3,4 etc , each time the cursor goes through , I will get one value in the variable - Offer
    So I want to pass that value to the select statement.. how do i do it?
    the one below does not work.
    drop table L1;
    create table L1
    (col1 varchar(300) null) ;
    insert into L1 (col1)
    select filter_name from table1 ;
    SET SERVEROUTPUT ON;
    DECLARE
    offer table1.col1%TYPE;
    factor INTEGER := 0;
    CURSOR c1 IS
    SELECT col1 FROM table1;
    BEGIN
    OPEN c1; -- PL/SQL evaluates factor
    LOOP
    FETCH c1 INTO offer;
    EXIT WHEN c1%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(offer);
    select * from table1 f where f.filter_name =:offer ;
    factor := factor + 1;
    DBMS_OUTPUT.PUT_LINE(factor);
    END LOOP;
    CLOSE c1;
    END;

    Hi Greg,
    Thanks for the response, No there is no ODB.net involved here.
    If I remove the : from :offer. I get this error now.
    Changed SQL is:
    select * from table1 f where f.filter_name =offer ;
    Error report:
    ORA-06550: line 16, column 23:
    PL/SQL: ORA-00942: table or view does not exist
    ORA-06550: line 16, column 9:
    PL/SQL: SQL Statement ignored
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Dynamic Parameter LOV Select Statement

    I have a parameter form with a value for the fiscal year and equipment ID. I want to populate the equipment ID list of values based on the fiscal year that is selected.
    My query for the equipment ID list of values would be SELECT EQPID,NAME FROM EQPLIST WHERE FY = :FY.
    When I tried to add this query to the list of values of the equipment ID parameter I get REP-0781: Bind variables are not allowed in the Select statement.
    Is there a way to dynamically generate the list of values select statement in a reports trigger?

    Hi,
    What version of Oracle Reports are you using?
    Unfortunately, it is a limitation of Oracle Reports to not restrict values based on other parameters - for sure until Reports 6i and I believe until the recent new versions.
    The other way to do what you want to do is to do it outside of Reports, if you have an Oracle Forms application. For example, you can create a simple Oracle Form that captures the Report parameters and then submits the report from the Forms. In Forms, you can implement the solution you are looking for - restricting values based on values of other parameters. In reports, you can't do that.
    If you have a few other reports that have similar requirements, then you can create a form to launch reports and submit all your reports from there after capturing all your parameters there.
    Venkat

Maybe you are looking for

  • Moving music from one computer to another using an iPod?

    Thing is I want to buy a new laptop soon, and I'd like to move my music from my old computer to the new one, but I'd like to use my iPod 160GB as a hard disk to transport it, I've copied my music and video files along with other important data into f

  • BT "Fixed" my connection now it's 25% slower

    I'm sure I'm not the first and won't be the last to have this issue. I had a problem with my connection where the speed dropped to around 0.3 to 0.5 Mb. Before my issues my connection speed was around 3.2-3.3Mb. Now my speed never goes above 2.36Mb.

  • Use of CALL FUNCTION - STARTING NEW TASK parameter_list.

    SELECT strt_code              city_code              commu_code              regiogroup       INTO TABLE gt_adrstreet1       FROM adrstreet       FOR ALL ENTRIES IN gt_street_district       WHERE strt_code EQ gt_street_district-strt_code. To optimize

  • Feature missing in Elements 9 for removal of dust specks in scan?

    I now use Adobe Photoshop Elements 9.  In an earlier version - possibly Elements 6 - as a scan was being queued, there was a check-off to use a feature that eliminated, in the scan, small flecks of dust.  I can't find that feature in Elements 9 - is

  • HTML into Flash please help!

    I want to put a HTML webpage into a certain field that is scrollable and when a link is clicked that box will change to give the content from the new page in that field ... please help, and also can javascript hover-off links from a webpage be put in