Does FOR i IN 1..10 Uses Cursor?

Hi,
Yesterday i was conducting an interview and was asking questions related to cursor. I asked the candidate to explain about Implicit cursor.
He gave me an example like this.
for i in 1..10
loop
end loop; At a first look it felt he was wrong. Because oracle creates a Cursor only for SQL statements. But then after the interview i started to think how oracle processes this? How is 1..10 is processed. What memory does it use?
Not sure if this is a silly question ;)

user2361373 wrote:
So 1..N IS not a cursor But this also needs memory to Fetch the results based on 1..N.Incorrect - there is no fetch. There is an implicit loop variable that is defined (which would be a 2 or 4 byte number in most languages - and usually needs an explicit variable definition).
This variable is incremented (the step clause in some programming language FOR loop statement). A condition is added to check whether another iteration is required, prior to incrementing the variable.
So in simple (and ugly) pseudo code, it looks something as follows:
define loop_var number := loop_start_counter;
:loop_start_label
if loop_var < loop_stop_counter {
  <loop body>
  loop_var++;
  goto :loop_start_label
}So it is really not a complex processing structure that the compiler creates.

Similar Messages

  • How to use Cursor Paramter

    Hi all,
    My query will written values by passing 5 parameter values.
    Now i want to use this query in plsql cursor, For that i need to use cursor parameter concepts and its very new to me. so pls any one help me how to use this cursor parameter to pass the values when i run my procedure.
    Regards
    Ajantha

    If you mean writing cursor with parameters you could try this way.
    CURSOR c1 (name VARCHAR2, salary NUMBER) IS SELECT ...
    --- open the cursor:
    OPEN c1(emp_name, 3000);
    Link for more info
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/06_ora.htm#36656
    Thanks

  • How to use cursor function for nested xml

    Hi,
    i have a query for XMLQuery like
    select * from bills where bill_id=????
    it results in something like
    <bills>
    <bill>
    <city>london</city>
    <amount>44</amount>
    </bill>
    <bill>
    <city>london</city>
    <amount>988</amount>
    </bill>
    <bill>
    <city>new york</city> <amount>59</amount> </bill>
    </bills>
    but i want xml output to be sorted for city names adding one more level location like
    <bills>
    <location city="london">
    <bill>
    <amount>44</amount>
    </bill>
    <bill>
    <amount>988</amount> </bill>
    </location>
    <location city="new york">
    <bill>
    <amount>59</amount> </bill>
    </location>
    </bills>
    it should be possible to iterate through the same table to gather informaton with the help of cursor function, but never used CURSOR before.
    any idea?

    sreese wrote:
    p_desig works as a comma delimited string without the NVL function, that's not the issue.
    It IS the issue .. you need to provide  a SAMPLE so we can see what you're doing ..
    How are you "passing it in" ?
    option A:
    procedure ( in_var  in  VARCHAR2 )
    AS
    and nvl(sn.c_attribute1,'x@#$%') in nvl(in_var,'x@#$%')
    option B:
    and nvl(sn.c_attribute1,'x@#$%') in nvl(&1,'x@#$%')
    .. or some other method?

  • Need using cursor for query

    Hi all,
    can anybody tell me how to get the result of the following query by using cursor?
    SELECT (SUBSTR('        ', 1,LEVEL*2)
      || t1.label) AS t1_label,
      amount
    FROM
      (SELECT t1.label,
        t1.ID,
        t1.parent_id,
        SUM(t2.turnover) AS amount
      FROM t1,
        t2
      WHERE t2.t1_id = t1.id
      AND t2.t1_id  IN
        (SELECT id
        FROM t1
          START WITH t1.ID       = 2
          CONNECT BY PRIOR t1.ID = t1.parent_id
      GROUP BY t1.label, t1.ID, t1.parent_id
      ) t1
      START WITH t1.ID       = 2
      CONNECT BY PRIOR t1.ID = t1.parent_id;...and the result:
    t1_label             amount
         B11     11778.54
          B121     19980.28
            B1211     18842.77
            B1212     25480.56
          B122     18339.07
        B12            23455.9
        B13            20876.52Thanks,
    Alex
    Edited by: 860003 on Jun 9, 2011 1:30 AM
    Edited by: 860003 on Jun 9, 2011 1:31 AM
    Edited by: 860003 on Jun 9, 2011 1:31 AM

    860003 wrote:
    Is not that i don't want to use hierarchy queries, but find others ways, tricks to reach the result needed. I just want to explore different ways that Oracle provides to resolve issues.Not a problem with that in principle.
    Maybe using "loop, if-else, for" will provide us with an elegant way to get the result. However, a problem in principle with this. SQL and PL/SQL are not the same thing. Two separate and very different languages.
    In PL/SQL, you can code both PL and SQL - so you can write source code of 2 different language and mix these. The PL/SQL parser is clever enough to figure out what is what and glues the code seamlessly and transparently together.
    SQL is used to crunch SQL data. PL/SQL sucks at this in comparison (and Java/.Net sucks a heck of a lot worse at this). Cursor fetch loops? Bulk processing. Neat. But will always be slower than running that data crunching in SQL only.
    That is why there is a simple maxim for performance in Oracle: Maximise SQL. Minimise PL/SQL.
    Do not use PL/SQL to do what the SQL is perfectly able and capable of doing. The exception is when the processing is too complex for SQL to handle and you need the programming logic part of the PL/SQL language.
    My question is how to use this cursor to get the value, fetch it and then get another value(ofc only for the children) and fetch it again so i can output it? I thing this can be achieve but don't know how.All SQLs (and anonymous PL/SQL) are parsed and cursors are created. A cursor is a basically a set of instructions (as seen via execution plans) of how to get the job done. Think of cursors as programs that are executed and output data.
    So do you want t create a bunch of cursors (programs) and then call these from PL/SQL, consume their output, create/call new cursor programs and repeat?
    Or do you want to create a single cursor program that does the job and outputs the required results?
    Maximise SQL. Minimise PL/SQL.

  • I can't send email from my iPad. I am from Australia but on holidays in Greece. Does anyone know what is the smtp outserver for Greece that I should use?

    I can't send email from my iPad. I am from Australia but on holidays in Greece. Does anyone know what is the smtp outserver for Greece that I should use?

    As you haven't told us who your email provider is, no.
    There isn't an SMTP server for Greece - it is either provided by your email provider, or the Internet provider you are connected through.

  • Why use cursor and for loop?

    Hi All
    So in general why would we use a cursor and a for loop to do update in a stored procedure?
    Why wouldnt we just use a single update statement ?
    is there compelling reason for using a cursor and a for loop: I am reading some code from a co-worker that the business logic for the select (set need to be updated) is complex but the update logic is simple (just set a flag to (0 or 1 or 2 or 3 or 4).
    But eventually the select come down to a key (row_id) so I re-write it using just a single sql statement.
    The size of the main table is about 2.6 to 3million rows
    Any thoughts on that??
    The code below I just do a google for cursor for update example in case for something to play with
    -Thanks for all your input
    create table f (a number, b varchar2(10));
    insert into f values (5,'five');
    insert into f values (6,'six');
    insert into f values (7,'seven');
    insert into f values (8,'eight');
    insert into f values (9,'nine');
    commit;
    create or replace procedure wco as
      cursor c_f is
        select a,b from f where length(b) = 5 for update;
        v_a f.a%type;
        v_b f.b%type;
    begin
      open c_f;
      loop
        fetch c_f into v_a, v_b;
        exit when c_f%notfound;
        update f set a=v_a*v_a where current of c_f;
      end loop;
      close c_f;
    end;
    exec wco;
    select * from f;
    drop table f;
    drop procedure wco;
    Joining multiple tables
    create table numbers_en (
      id_num  number        primary key,
      txt_num varchar2(10)
    insert into numbers_en values (1, 'one'  );
    insert into numbers_en values (2, 'two'  );
    insert into numbers_en values (3, 'three');
    insert into numbers_en values (4, 'four' );
    insert into numbers_en values (5, 'five' );
    insert into numbers_en values (6, 'six'  );
    create table lang (
       id_lang   char(2) primary key,
       txt_lang  varchar2(10)
    insert into lang values ('de', 'german');
    insert into lang values ('fr', 'french');
    insert into lang values ('it', 'italian');
    create table translations (
      id_num    references numbers_en,
      id_lang   references lang,
      txt_trans varchar2(10) not null
    insert into translations values (1, 'de', 'eins'   );
    insert into translations values (1, 'fr', 'un'     );
    insert into translations values (2, 'it', 'duo'    );
    insert into translations values (3, 'de', 'drei'   );
    insert into translations values (3, 'it', 'tre'    );
    insert into translations values (4, 'it', 'quattro');
    insert into translations values (6, 'de', 'sechs'  );
    insert into translations values (6, 'fr', 'six'    );
    declare
      cursor cur is
          select id_num,
                 txt_num,
                 id_lang,
                 txt_lang,
                 txt_trans
            from numbers_en join translations using(id_num)
                       left join lang         using(id_lang)
        for update of translations.txt_trans;
      rec cur%rowtype;
    begin
      for rec in cur loop
        dbms_output.put (
          to_char (rec.id_num         , '999') || ' - ' ||
          rpad    (rec.txt_num        ,   10 ) || ' - ' ||
          rpad(nvl(rec.txt_trans, ' '),   10 ) || ' - ' ||
                   rec.id_lang                 || ' - ' ||
          rpad    (rec.txt_lang       ,   10 )
        if mod(rec.id_num,2) = 0 then
          update translations set txt_trans = upper(txt_trans)
           where current of cur;
           dbms_output.put_line(' updated');
        else
          dbms_output.new_line;
        end if;
      end loop;
    end;
    /Edited by: xwo0owx on Apr 25, 2011 11:23 AM

    Adding my sixpence...
    PL/SQL is not that different from a SQL perspective than any other SQL client language like Java or C# or C/C++. PL/SQL simply integrates the 2 languages a heck of a lot better and far more transparent than the others. But make no mistake in that PL/SQL is also a "client" language from a SQL perspective. The (internal) calls PL/SQL make to the SQL engine, are the same (driver) calls made to the SQL engine when using Java and C and the others.
    So why a cursor and loops in PL/SQL? For the same reason you have cursors and loops in all these other SQL client languages. There are the occasion that you need to pull data from the SQL engine into the local language to perform some very funky and complex processing that is not possible using the SQL language.
    The danger is using client cursor loop processing as the norm - always pulling rows into the client language and crunching it there. This is not very performant. And pretty much impossible to scale. Developers in this case views the SQL language as a mere I/O interface for reading and writing rows. As they would use the standard file I/O read() and write() interface calls.
    Nothing could be further from the truth. SQL is a very advance and sophisticated data processing language. And it will always be faster than having to pull rows to a client language and process them there. However, SQL is not Turing complete. It is not the procedural type language that most other languages we use, are. For that reason there are things that we cannot do in SQL. And that should be the only reason for using the client language, like PL/SQL or the others, to perform row crunching using a client cursor loop.

  • Oracle BPEL - Does not cater for not null columns and use of "default".

    Oracle BPEL - Does not cater for not null columns and use of "default".
    BPEL fails with message:
    ORA-01400: cannot insert NULL into ("EDDB"."SEISMIC_LINES"."COORD_SYSTEM_ID")
    But SQL*PLUS command works:
    INSERT into EDDB.SEISMIC_LINES
    (etc)
    regards
    Allan Ford
    Analyst / Programmer - IT Application Services, IT Services, Shared Business Services
    Santos Ltd
    Level 4, 91 King William Street, Adelaide SA 5000
    Phone: 08 8224 7944 Fax: 08 8218 5320
    Email: [email protected]

    note: BPEL keeps it's own "offline" copy of table and database items. A column that is marked not null in the database can be marked as nullable in this area. (if you kmow that a trigger is going to cater for this ..)
    One workaround is to use a trigger to provide value rather than use the column default ..

  • After reopening Firefox does not remember which desktop was used for each window. Can you help, please.

    I'm using two displays and several desktops on my Mac (OS X 10.9.4).
    When I need to restart Firefox, it remembers to open windows from last session in correct display, but does not remember which desktop was used for each window. So when the application starts, it opens all windows on a desktop which is currently active instead of reopening them on desktops used during the last session. How to fix the issue?

    Hi Nerva,
    Thank you for your question, there is a add on I have been recommended to custom set up of opening windows in new monitors. It's called [https://addons.mozilla.org/en-US/firefox/addon/monitor-master/ Monitor Master].
    However, in regards to the session remembering which monitor the window was open in, in the profile folder there is a file that stores window positions and dimensions. It is called localstore.rdf.
    Please stay tuned for more investigation, as there are definitely bugs on file for similar issues. Pinpointing it is the hard part.

  • Does anyone know what ppqryErrorList is used for in EssOtlQueryMembersEx?

    Given a calcscript, I'm wondering if I can get a list of errors back it has multiple errors (e.g. member not found, syntax error etc.) when I run EssOtlQueryMembersEx.
    I've looked at the documentation (http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/html_esb_api/api_c/otlc/funcs/apcfqmex.htm) and looks like ppqryErrorList does the job for me. However, I'm getting a NULL pointer to ppqryErrorList regardless or whethere there's an error or not.
    e.g. when I call "@ICHILD(blah)" with EssOtlQueryMembersEx I'm hoping the error list (ppqryErrorList) will contain "member not found blah" but it infact returns NULL.
    This parameter on EssOtlQueryMembersEx must be there for a reason. Does anyone know what this is used for?
    Btw, I'm using Essbase 7
    -Steve

    Well, After Effects has a shattering effect, but I'd guess it was a 3D app that created those effects. To see what you can do with Motion, check out this thread:
    Fun with Shattering...
    Patrick

  • Iphone 4 sync issue -  My iTunes is not able to sync the iPhone 4. I'm using windows 7 32bit. At the first step it gets stuck refelcting backing up the phone then nothing happens for ages. I'm using the latest iTUnes version, does anyone have similar prob

      My iTunes is not able to sync the iPhone 4. I'm using windows 7 32bit. At the first step it gets stuck refelcting backing up the phone then nothing happens for ages. I'm using the latest iTUnes version, does anyone have similar prob??? There are no error codes which appear and the iTUNES just gets hanged, is there a solution?

    Remove the song in question from the sync list and see if the rectifies the problem.
    If it does, then iTunes believes the song no longer exists on your drive and that will need to be corrected.

  • HT5622 I had this pop up: Add (phone number) for Facetime and iMessage. This phone number was associated with AppleID  on iPhone. I havent used it or done anything. What does this mean? Is someone using my ID and do they have my pasword.?

    I had this pop up: Add (phone number) for Facetime and iMessage. This phone number was associated with AppleID  on iPhone. I havent used it or done anything. What does this mean? Is someone using my ID and do they have my pasword.?

    If it isn't from something you did (like update iOS on an iPhone, or activate a new iPhone), then yes, I would be suspicious.

  • Ipad2 does not change orientation. I have not used the switch for lock rotation it is used for mute

    Ipad2 does not change orientation. I have not used the switch for lock rotation it is used for mute

    Is there a lock symbol at the top of the screen next to the battery indicator ? If so, and as you've got the switch set to notification mute, then have you checked the taskbar (the function that the switch isn't set to is controlled via the taskbar instead) : double-click the home button, slide the taskbar to the right, and it's the icon far left.
    If you havn't got the lock symbol at the top then try a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • HT1725 I have been trying to purchase points for a slot machine game using my itunes card. It has subtracted all the $$$$ off the card but I never got the points. Not sure what I am doing wrong. Have restarted the ipad and still nothing.

    I have been trying to purchase points for a slot machine game using my iTunes gift card. It subtracted the right about of $$$ but never gave me my points....not sure what I am doing wrong.
    Any help will be appreciated!

    Contact iTune Support
    https://ssl.apple.com/emea/support/itunes/contact.html

  • HT204088 Does anyone know how to speak to customer service for iTunes? I got charged for something and have no clue what I got charged for. I have not used iTunes yet. There is no way on the apple site to get this resolved.

    Does anyone know how to speak to human being in customer service for iTunes? I got charged for something and have no clue what I got charged for. I have not used iTunes yet. I have spent a lot of time trying to get this resolved on the apple site and there just seems no way to do it. Thanks.

    iTunes Customer Service is an online service unless they feel they need to call you.
    iTunes Customer Service Contact - http://www.apple.com/support/itunes/contact.html > Get iTunes support via Express Lane > iTunes > iTunes Store

  • HT201304 I have been trying for two weeks to log into iTunes using my Bank of America Visa Debit card but no progress. Is it that iTunes does not use debit card, I only have a debit card and  Not credit card, so does it mean I can't use iTunes .?

    I have been trying for two weeks to log into iTunes using my Bank of America Visa Debit card but no progress. Is it that iTunes does not use debit card, I only have a debit card and  Not credit card, so does it mean I can't use iTunes .?

    I believe if you haven't already setup an itunes account, if you have access to computer with iTunes installed , you can create an iTunes account on that computer with no credit/debit card and then just buy iTunes cards at your local retailer to get credits.

  • Purchased ExportPDF for one of our end using depts.  It is under my account I manage for our institution.  How does the dept get the application to download.

    Purchased ExportPDF for one of our end using depts.  It is under my account I manage for our institution.  How does the dept get the application to download.

    Hi Cassi,
    If you are ordering subscriptions for various people in your office, it would be best to sign up under their Adobe IDs, so they can log in and use the subscription with their own credentials. As for moving the current subscription, the easiest route is to cancel the current subscription (see Cancel your membership or subscription | Acrobat, Acrobat.com online services--or I can help), and then reorder as necessary.
    Best,
    Sara

Maybe you are looking for