Using a cursor to reference in a loop for.

I have a procedure with a few loops for nested that finds consecutive intervals with different ranges of entry into force. It looks something like this.
declare

cursor c1 (p1 in date, p2 in date, p3 in date) select col1,col2,col3,col4 from a_table where col1 = p1 and p2 between col2 and col3..(more conditions)..;
cursor c2 (p1 in date, p2 in date, p3 in date) select col1,col2,col3,col4 from a_table where col1 = p1 and p2 between col2 and col3..(more conditions)..;
cursor c3 (p1 in date, p2 in date, p3 in date) select col1,col2,col3,col4 from a_table where col1 = p1 and p2 between col2 and col3..(more conditions)..;

begin

for x1 in c1(start1, start2, start3)
loop
  --print stuff from x1.col1 x1.col2 x1.col3 x1.col4
  for x2 in c2(x1.col4, x1.col2, x1.col3)
  loop
    --print stuff from x2.col1 x2.col2 x2.col3 x2.col4
    for x3 in c3(x2.col4, x2.col2, x2.col3)
    loop
      --print stuff from x3.col1 x3.col2 x3.col3 x3.col4
    end loop;
  end loop;
end loop;
end;
/
.. .cursor for loops are nice and clean, do not have to worry about pick... works perfectly.

But I don't like that I have 3 sliders with the same exact query. I would rather define it only once if possible. I tried to do it with the ref Cursor, but it looks like I can't use ref Cursor in a for loop in the same way you can with a plain ol' slider.

Is there a way to get what I'm doing? A single cursor definition reused within nested for loops without worrying about opening/extraction/closing anything?

DylanB123 wrote:
For some reason any I Although pl/sql did not support recursion. Maybe it's the ticket.
>

For some reason any I Although pl/sql did not support recursion. Maybe it's the ticket. PL/SQL doesn't support recursion, but it is allowed. You can do it, but you're on your own to make it work :)

Tags: Database

Similar Questions

  • Using 'New data value reference' in a loop

    Hi all

    I just read on the data value references (DVR?) and I'm trying to use them with overall functional (see table).

    I don't think that I'm just doing.  The final goal is a producer/consumer nickname.  My concern is that I don't feel the implementation of the new primitive data value reference and re-stuffing the result in the FGV, should occur in each loop.

    Of course I could "spread" data with a single gueue element (where the queue of new data would take place each loop).  I just thought that I would play with them.

    Beavercreek wrote:

    I think that we defend the same point, but I can't seem to understand why this does not work the way I expected.  I discovered the DVR (and queues) as a pointer, simply a way that the other vi can know where the data is located.  The data that we are after is here.  So, why Ch1 does not work in the data_reader.vi?

    If we can get Ch1 to work data_reader without re-creating and re-writing of the reference in the FGV each pole (what does Ch2), we find no more what is wrong with my vI or I'm going to learn something that is still beyond me.  I hope to hit me in the head this afternoon still

    You are missing a fundamental idea: the function you call creates a reference that points to a specific value. To actually interact with this value (read/write), you need to use the structure of the International preliminary examination. At this time what you are creating a single reference for ch1 (which do you nothing with) and creation of multiple references to ch2 (where at each iteration that you replace the reference in the FGV, so you basically lose the old reference), so instead of having two DVRs, you really N + 1 DVR (where N is the number of iterations of the loop runs).

    For your code works the way you want, you only need to create two digital video recorders (probably before the loop), then bring them inside the loop and use the structure of the International preliminary examination with nodes in R/W DVR to set the value in the DVR.

    For example:

    Other problems with the code, but this deal the DVR issue.

  • When to use the cursor for loop and the cursor (open, fetch, close)

    Hello world
    I have a small doubt about when to use the cursor for loop and when to use the cursor for loop and the cursor (open, fetch, close).
    Well, I'm not the difference between implicit and explicit cursor. So please tell me how I got to know, what to use and when?




    Kind regards
    BS2012

    Published by: BS2012 on January 29, 2013 12:15

    All SQLs are analyzed, stored and executed as cursors. Thus, you will always use a cursor.

    The problem is that languages, such as PL/SQL, provide different interfaces to interact with the SQL cursor. As the ref, the slider interface, the interface DBMS_SQL slider interface and so on.

    Each of these interfaces offers different features. For example, using the interface DBMS_SQL allows binding dynamics and dynamic recovery. The Ref Cursor interface allows your code PL/SQL pass a handle to a reference pointing to the SQL cursor, to an external client. Etc.

    The fundamental reason for the use of an explicit cursor interface is mainly that you own and manage bulk made extraction output provided by PL/SQL cursor.

    With a cursor FOR , the motor loop of PL/SQL optimize the loop by extracting block a 100 lines both. However, you cannot access this collection in bulk directly inside the loop.

    With an explicit cursor interface, you specify the size of the extraction in bulk via the clause LIMIT , and you set the variable of collection to use. This allows you to use the collection directly variable inside the loop.

    However, the need to do - code manually in bulk collection - rarely occur in the daily programs in PL/SQL. A line of treatment is both slow and not well fits. And even if your bulk code collects lines, these lines must still be processed one at a time in your code. It is much more efficient and scalable rather write SQL code, and make the engine SQL the line of treatment for you.

  • Control reference 1055 error when you use a loop for

    Hello

    I'm having a problem using control references to accomplish the following: I a VI that reads data from a text file, and then uses that automatically update the value of a control on front panel on two live different, then set the default values, and then save them. Comes from the array of control references, I tried looping on text labels until I have find the one corresponding to the order, I want to change and then update its value. The problem I have is that if I use a loop for, then 9times of LabVIEW 10 complains error 1055: "LabVIEW: object reference is not valid. If instead I the wiring to the index table and manually extract the reference, then it works every time and for each index of the reference of the order.

    Can someone take a look at my code and just see if its obvious what the problem is? In this case, I have a simple solution, but I would really like to understand what I did wrong. I have included as a code snippet, but also attached the files if that helps (Its Import_Colormap.vi, which is the problem). Persons with disabilities code fails, the active code works but I can't see what is really the difference between them - I can change the index of array 0,1,2, 3. and no mistake.

    Thank you.

    Your "Colormap.ctl" is a strict type def that contains a ring.  You define the elements programmatically, make the default values, and then save the "Colormap.ctl"?   I was never practicing this but here is a thread that covers this in detail. I do not understand what you expect reach by running.
    The next thing: at the same time (at the same time!), you open the Colormap.vi (this is what we see in yout PNG) that contains an instance of the Colormap.ctl on the front panel. I'm not pretty sure if LabVIEW can handle this correctly. This could be the reason why you sometimes get the error 1105.
    I prefer StringsAndValues and eventually the value of the ring running.  There is no need to do it with a def of strict type.

  • How to query an array type without using Loops(FOR,etc)

    Hi all

    I'm just a beginner working with oracle DB. I have a basic question about the TYPES of TABLES in oracle.

    creating table example (a number, b varchar2 (10))
    /
    Set serveroutput on;

    declare
    TYPE tab_type IS TABLE of example % ROWTYPE;
    t_tab tab_type: = tab_type();
    Start

    I'm IN 0.2
    loop
    t_tab.extend;
    t_tab (t_tab.last) .to: = i;
    t_tab (t_tab.last) .b: = "maru";
    dbms_output.put_line (t_tab (t_tab. (Last) .at);
    end loop;

    -What I CAN DO SELECT * FROM THE TABLE t_tab without using a cursor to iterate line by line
    -Since I need to compare the values in a table called HAND with this SAMPLE table.i need to check if all the files present in the table MAIN is present in the
    -Type of table table SAMPLE. I do not want to insert into a temporary table (because it becomes an overhead projector) and compare the results.
    end;

    Kindly help me in this regard and let me know if you need more details.

    Thanks in advance.

    Maybe you would like

    create type mytype as object
    (
    a number,
    b varchar2(10)
    );
    /
    create type tab_type as table of mytype;
    /
    declare
    t_tab tab_type := tab_type();
    sRES varchar2(10);
    begin
    for i IN 1..2
    loop
    t_tab.extend;
    t_tab(i) := mytype(i,'maru');
    end loop;
    
     select b
     into sRES
     from table(cast(t_tab as tab_type))
     where a = 2;
     dbms_output.put_line(sRES);
    end;
    /
    

    Published by: Alkaron on 27.03.2012 08:37

  • How to modify a statement "select into" how to use a cursor

    The following code fails with an exception too many lines. How can I modify statement Select Into the procedure to use a cursor?
    CREATE OR REPLACE PROCEDURE Track_Asset(
       business_date IN NUMBER DEFAULT NULL,
       missing_table_name  OUT VARCHAR2) 
    IS
       ln_business_date NUMBER;
        incorrectdateformat EXCEPTION;
    BEGIN
       IF business_date < 0 
       THEN
          RAISE incorrectdateformat;
       ELSE
          DECLARE
            ln_business_date NUMBER;
          BEGIN
             SELECT MAX(business_date) 
             INTO ln_business_date
             FROM sproof ;
          EXCEPTION
            WHEN NO_DATA_FOUND THEN
             dbms_output.put_line('NO MATCH FOUND'); 
            WHEN OTHERS THEN
            dbms_output.put_line('ORACLE ERROR :' || SQLERRM);        
          END;
          
          DECLARE
            missedfeedfnd EXCEPTION;
          BEGIN
             SELECT 'Missing Value : ' || table_name 
             INTO missing_table_name 
             FROM ( 
                SELECT UPPER(table_name) table_name 
                FROM filespec
                WHERE data_table_name IN ('TABLE1','TABLE2','TABLE3') 
                MINUS ( 
                SELECT DISTINCT UPPER(first_table_name) 
                FROM dpca
                WHERE business_date = ln_business_date 
                AND first_table_name IN ('TABLE1','TABLE2','TABLE3') 
                GROUP BY UPPER(first_table_name) UNION 
                SELECT UPPER(first_table_name) 
                FROM dpca
                WHERE business_dt_num = TO_NUMBER( SUBSTR('201111', 1, 6) || '01' )
                AND first_table_name = 'TABLE4' 
                GROUP BY UPPER(first_table_name) ));
                
                IF missing_table_name  IS NOT NULL THEN
                   dbms_output.put_line('Missing Value : '|| missing_table_name);
                   RAISE missedfeedfnd;
                ELSE
                  NULL;
                END IF;
          EXCEPTION
             WHEN TOO_MANY_ROWS THEN
       DBMS_OUTPUT.PUT_LINE (' SELECT INTO statement retrieved multiple rows');
              WHEN missedfeedfnd THEN 
              raise_application_error ( - 20003, 'Missed Feed');
          END;
        END IF;
          EXCEPTION
       WHEN incorrectdatevalue 
       THEN
          raise_application_error ( - 20001, 'Incorrect/Bad Date Entered');
    END;

    OK, try this - OUT param will be filled with the table names comma-separated list:

    PROCEDURE Track_Asset(
       business_date IN NUMBER DEFAULT NULL,
       missing_table_name  OUT VARCHAR2)
    ...
    ...
    
    cursor c_table_names is
    select datatablename
    from   ( select upper(datatablename) datatablename
             from   filespec
             where  data_table_name in ('TABLE1','TABLE2','TABLE3'                                 )
            MINUS
            ( select upper(first_table_name)
              from   dpca
              where  business_dt_num = [-- this date is retrieved by getting the MAX(business_date) from sproof table]
                     and fus_data_table_name in ('TABLE1','TABLE2','TABLE3'
                                                )
              group  by
                     upper(first_table_name)
             UNION
              select upper(first_table_name)
              from   dpca
              where  business_dt_num = to_number( substr('201111',1,6) || '01' )
                     and first_table_name = 'TABLE4'
              group  by
                     upper(first_table_name)
            ));
    
    ...
    ...
    begin
       ...
       for rec in c_table_names
       loop
           missing_table_name  := missing_table_name  || rec.datatablename ||',';
       end loop;
       missing_table_name  := rtim(missing_table_name , ',');
    ...
    ...
    end ;
    

    HTH

    Published by: user130038 on December 28, 2011 08:46

  • For loop for cursor

    Hello
    I have a table used as follows
    SQL> desc employees
     Name                                      Null?    Type
     ----------------------------------------- -------- ---------------------
    
     EMPLOYEE_ID                               NOT NULL NUMBER(6)
     FIRST_NAME                                         VARCHAR2(20)
     LAST_NAME                                 NOT NULL VARCHAR2(25)
     EMAIL                                     NOT NULL VARCHAR2(25)
     PHONE_NUMBER                                       VARCHAR2(20)
     HIRE_DATE                                 NOT NULL DATE
     JOB_ID                                    NOT NULL VARCHAR2(10)
     SALARY                                             NUMBER(8,2)
     COMMISSION_PCT                                     NUMBER(2,2)
     MANAGER_ID                                         NUMBER(6)
     DEPARTMENT_ID                                      NUMBER(4)
    I want to make a slider that retrieves the last_name, salary, and the Manager id
    It's the employees who work in a specified service I will enter id
    a value of substitution (&).
    for 4 departments of loop for.
    I tried this code but it does not give me the required result
    SQL>  declare
      2     v_deptno  number :=&dept_id ;
      3      last varchar2(20);
      4    sal number;
      5     manager number;
      6     cursor c_emp_cursor is select last_name,salary ,manager_id from employee
    s
      7     where department_id = &v_deptno;
      8    begin
      9     open  c_emp_cursor;
     10     for i  in 1..5  loop
     11     Fetch  c_emp_cursor into last,sal,manager   ;
     12     dbms_output.put_line(last||'            '||sal||'         '||manager);
     13     end loop;
     14
     15     end;
     16     /
    Enter value for dept_id: 10
    old   2:    v_deptno  number :=&dept_id ;
    new   2:    v_deptno  number :=10 ;
    Enter value for v_deptno: 20
    old   7:    where department_id = &v_deptno;
    new   7:    where department_id = 20;
    Hartstein            13000         100
    Fay            6000         201
    Fay            6000         201
    Fay            6000         201
    Fay            6000         201
    
    PL/SQL procedure successfully completed.

    Hello

    VDH says:
    ... The code well work OK, but not exactly as I want.
    I want, for example, data from five departments. (not only a Department).

    It's not what you said in your first post:

    VDH says:
    ... I want to make a slider that retrieves the last_name, salary, and the Manager id
    It's the employees who work in a specified service I will enter id
    by a value (&) substitution.

    You want 1 Department or 5 departments?
    If you use a substritution variable (let's call it department_list), you can enter a list of departments, separated by commas (but), for example

    10,40,70,20,110
    

    and use it in a condition like

    WHERE   department_id IN (&department_list)
    

    This works if the list has 1 point, 5 (or any other number). The user can decide how to enter the runtime.

    Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements).
    Also post the results you want from these data (in this case, the output you want from put_line), as well as an explanation of how you get these results from these data, with specific examples.
    If your problem is with the parameters (such as the intervention of the user) put a couple of different sets of parameters and the results you want the same data for each set of parameters.
    If you use a commonly available table (suhc as hr.employees), then you need not to display sample data, just the results and explanations.
    Always tell what version of Oracle you are using.

  • CURRENT OF refuses to use my cursor - why?

    On Oracle 11.2
    create or replace
    procedure example
    is
    row TABLE1%ROWTYPE;
    c1 sys_refcursor;
    BEGIN
         open c1 for
              SELECT * from TABLE1 where foo = 1 order by prim_key FOR UPDATE SKIP LOCKED;
    
         LOOP FETCH c1 INTO row;
              EXIT WHEN c1%NOTFOUND;
                   UPDATE TABLE1 SET
                        bar = 2
                   WHERE CURRENT OF c1;
         END LOOP;
         CLOSE c1;
    END;
    /
    Gives this error:
    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    11/4     PL/SQL: SQL Statement ignored
    13/21    PL/SQL: ORA-00904: : invalid identifier
    13/21    PLS-00413: identifier in CURRENT OF clause is not a cursor name
    What's wrong? I guess it's something minor that I neglected.

    Kind regards
    David

    xerces8 wrote:

    If I use a slider like this explicit:
    Is it in terms of the order of execution as if with a

    Yes, and I see no reason to use ref cursor.

    SY.

  • Cursor inside a loop FOR?

    Hello

    We will declare or define a cursor inside a loop FOR?

    -Vijay

    Yes, it is possible that the definition take place inside the part of the plsql block code, the syntax looks like:

    for rec in (/*here you define cursor with select query*/) loop
      ...
    end loop;
    

    I think that if you do not use a variable/slider several times, it is advisable to set the cursor with the loop for. If you want to use the cursor over a school then it should be defined in more global place.

  • Selection of data with or without the use of cursors in procedures

    Hello

    If we are able to access the data without using a cursor as shown below in a way:


    CREATE OR REPLACE PROCEDURE tmr_exception
    IS
    x LINK_STATUS. COUNTRY_CODE % TYPE;

    BEGIN
    SELECT COUNTRY_CODE LINK_STATUS x;

    EXCEPTION
    WHEN TOO_MANY_ROWS THEN
    dbms_output.put_line (' too many lines).
    WHILE OTHERS THEN
    dbms_output.put_line ("' another problem");

    END tmr_exception;
    */*

    So what is useful in the use of explicit cursors?

    (1) SELECT... Return exactly 1 row. If you try to deal with several rows of data, you will need another construction.

    (2) A SELECT... INTO opens a cursor. He has simply done implicitly. Just like

    BEGIN
      FOR emp_cur IN (SELECT * FROM emp)
      LOOP
        <>
      END LOOP;
    END;
    

    Opens an implicit cursor.

    (3) no implicit and explicit cursors these days are generally useful when you do treatment in bulk and you want to extract the data in a local collection.

    Justin

    Published by: Justin Cave on October 9, 2010 20:17

    (4) oh and you would never have in real code catch an exception and do nothing else than calling DBMS_OUTPUT. It's a quick way to produce a totally unmanageable code.

  • Problems using trigger cursor query and post.

    Hello

    I use a block non-base of data/model to query records in a database block. My form has a point text 'report No.' that will be used to enter a valid number of reports. Based on the number of this report, I hit a button to search (also from the same block of data non-base) to view records that have this "report No.' in the database block. I think I need to use a cursor in a post for this request but I am not able to operate :( Help, please! I really need this point that nobody is helping me to work:(la figure)

    My search button - button the trigger:
    DECLARE
    NUMBER OF CHOICES;
    BEGIN
    IF: DUMMY_BLK. NWTFR IS NULL THEN
    ALERTS. STOP_ALERT ("Start Date is required", choice);
    RAISE FORM_TRIGGER_FAILURE;
    END IF;
    go_block ('T_VESSEL_BLK');
    execute_query;
    END;

    My post_query:

    DECLARE
    cursor vessel_cur is
    SELECT VES_RPTNO, VES_SENDER, VES_SENDER_MBOX, VES_INTCTRL_REF, VES_NAME, VES_VOYNO, VES_ARRDT
    SHIP
    WHERE VES_RPTNO =: DUMMY_BLK. NWTFR;
    var_mot vessel_cur % ROWTYPE;
    BEGIN
    Open vessel_cur;
    LOOP
    extract the vessel_cur in var_mot;
    EXIT WHEN vessel_cur % NOTFOUND;
    END LOOP;
    close vessel_cur;
    END;

    instead of execute_query you do now

    Why do you offer me something like that? Replacing the standard behavior that you use forms must be well thought out, because you have to manage a large number of possible problems. You can easily get the desired using the standard logic behavior:

    -Create an item number IT_COUNT in a control block, assign 'calculation mode' to 'Summary', 'Synthesis function' to 'Count' "Down block" and your DB-bloc and "just point' a null-element not contained in this block. Last series the block 'Interrogate all folders' to 'Yes' in your databaseblock. Now, in your code, you can just checkl the value of this element of count, as

    ...
    EXECUTE_QUERY;
    IF :BL_CONTROL.IT_COUNT=0 THEN
      error
    END IF;
    
  • If I use a single individual loop for my video and upload it to youtube will be my video will be blocked or will I get copy right strike?

    If I use a single individual loop for my video and upload it to youtube will be my video will be blocked or will I get copy right strike?

    I already read the agreements loops but unable to understand exactly what it means please help me...

    They say individual loops must not be commercialy or other wise distributed...

    That means individual loop should not be used?

    Is the only thing you can NOT do: "Yes, I did these loops and now I'm selling you these loops, claiming that I just them

    So they are free, but you are not allowed to sell unaltered loops claiming that make them you. So you can use them for any kind of music, published published, obscure, commercial, anything; without additional costs or restrictions.

    Hello... Please help me I want to just use a single loop of logic pro X for my video and want to download YouTube wil...

  • make a graph in real time of 1 DBL value at a time, using a loop for

    I have a somewhat interesting programming task where I have the following situation: (I have attached a mac version of vi Labview 2013)

    -Using a patented (pre-made and uneditable) sub - vi, who receives a value of 0 or 1 as input and reads off a single measure, whenever he receives 1 while a value of 0 is necessary to 'reset' of the vi to rehearse a new measure.

    -I would like to run this sub - vi repeatedly in a loop For each value of "measure" are sent to a curve of waveform to give a direct value (real time) for the graphic to display.

    -As it is, I have a vi file that simulates action in a loop but built in a 1 d array to get exuent values sent a waveform curve.

    -I don't know how to make a real-time graph which receives 1 value double both.

    -In addition, I want only every 2nd value sent to the loop for, but I already have several ideas on how to do it.  First of all, I am concerned about the target in real time.

    Kyle Shiel

    A graphic, not a graphic, allows you to update a point at a time. It would be inside the loop for. update the chart or not, you can use a select statement or the structure of the case.

    These are pretty basic functions in LabVIEW. Please see the free tutorials.

  • You can trigger through communication Modbus TCP/IP PLC data acquisition without using a loop for?

    Hello

    I am trying to contact a facility through a Modbus TCP/IP communication PLC. I'm new to this method, but the idea is that the installation will send the logical (Boolean) values 1 bit by ethernet to my workstation which read and then will begin data acquisition. Basically, I need a triger to come to my pc. I placed my vi inside a structure case T/F which will run according to the signal, it receives data acquisition. However, for it constantly waiting, I put this in a loop for. The works of vi, but playback signals sometimes lagging behind due to the loop for. If I take the loop out and just run labview permanently, it works perfectly, but I know that the option is only for debugging and should not be used. So my question is, is there a better way to wait for an incoming signal?

    Hello!

    Please note that the order of execution of the write operations on the shared variable 000002 is not determined.

    For example, nothing prevents this order of execution:

    (1) value false 000002

    (2) set to true 000002

    (3) execution of the loop

    In what concerns the delay, you might consider placing a waiting vi in the case of 'false', or the loop uses 100% of CPU if I'm not mistaken...

    Kind regards

    Marco

  • Iterate over all others (or number) of element in an array using a loop for

    I'm going through a table, but instead of autoindexing I want to ignore all the other elements or perhaps a number of elements that will be specified for the user.

    The basic features I want to reach are the next in C code.

    int temp_var = 10;

    int i = 0;

    for (i = 0; i<=1000; i="">

    {

    }

    I am very new to LabVIEW and I didn't know how to use internal variables.

    Can this be achieved using the registers at offset?

    I enclose the code that I currently have to do this. Let me know what you think.

    Thank you guys.

    You must implement this one a While loop with a shift register to hold the index.  The index must be changed by the step size.  Here is the code:

    I asked for a new style of loop For which would specify start, stop and the conditions of the stage, but it seems that a lot of people is just not this idea.  Don't know why?

    See here.

Maybe you are looking for

  • How can I use a wait with a tank xD ending function

    Hello I want to read a series of data per second. I tried to use an incentive (ms), but it does not work if I put a termination tank xD. How to read data series every second?

  • HP ENVY 14-1210NR display

    My HP Envy is not guaranteed. I bought in 2011 in the United States. In fact, I live in Mexico and I don't support hear. I need to display and support for my knees. Thank you!

  • Printing problems with Windows Vista

    I have Windows Vista. Every day or two if I am printing in Word, Excel, Internet Explorer, PDF, etc., the application crashes. The job does not print and gets stuck in the print queue.  This forces me to go in Control Panel > systems & maintenance >

  • Download the blackBerry Z10 software update for Z10 fails continually exactly 62%

    Software update download Z10 REPEATEDLY fails at 62% of the download.  Have used the site BBlink and BB using Firefox and IE with the same results... to 62% of the download, it fails and says: 'internet problem.'  Have you tried dozens of times with

  • Confusion between OS &amp; JDE

    Hello I developed application in jde 4.7. The code is designed keeping backwards compatibility with 4.5. So, now I want to test the code in the Simulator with OS 4.5. My confussion is: I would like to download jde 4.5 and add build my project inside