If statement in loop

for rec in cur loop
               dID := rec.update_id;
               dTYPE := rec.update_type;
               dNUMBER := rec.patch_number;
               dDESC := rec.description;     
               dOLD := rec.old_db_version;
               --search if patch is already installed, if Yes do nothing, else:
               if dID = cID then     
                    --now check version of DB
                    if cVER = version then
                    exec procedures(1);
          end loop;
Error on line 10
DECLARE
var NUMBER;
     version varchar(12);
     installed boolean;
     --var
ORA-06550: line 79, column 12:
PLS-00103: Encountered the symbol "PROCEDURES" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "PROCEDURES" to continue.
ORA-06550: line 82, column 10:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
why that if statement make for loop broken?

stil the same,. i will paste it there all :)
--testing procedure
set serveroutput on
create or replace procedure sampleP is
begin
dbms_output.put_line('write something');
end;
DECLARE
var NUMBER;      
     version varchar(12);
     installed boolean;
     --variables for reading from table in database - installed hotfix's
     dID varchar(128);
     dPACKAGE varchar(50);
     dSEQUENCE varchar(50);
     dNUMBER varchar(128);
     dBASE varchar(256);     
     dNEW varchar(128);
     --variables for reading from table in database - current hotfix
     cID varchar(128);
     cPACKAGE varchar(50);
     dSEQUENCE varchar(50);
     cNUMBER varchar(128);
     cBASE varchar(256);     
     cNEW varchar(128);                    
     --procedure's in array
     --array for procedures
     type p_procedures is table of varchar(100) index by pls_integer;
     procedures p_procedures;
     --array for hotfix , which version it have
     --it must match with procedures array
     type p_versions is table of varchar(100) index by pls_integer;
     versions p_versions;
     CURSOR cur IS SELECT update_id,update_type,patch_number,description,old_db_version FROM SWIZ_DB_UPDATE_HISTORY;
BEGIN
     --set hotfix installed to NO = 0
     --installed := 0;
     --sampleP;
     --execute procedures in field
     --first fill it with correct names
     procedures(1) := 'sampleP;';
     procedures(2) := 'sampleP1;';
--then execute them in loop
for v_rec in procedures.first .. procedures.last loop
--execute immediate 'begin ' || procedures(v_rec) || ' end';
     DBMS_OUTPUT.put(procedures(v_rec));
end loop;
     -- get the current version of database
     SELECT version INTO version FROM SWIZ_DB_VERSION;
     --info about current hotfix
     SELECT ID into cID from A_ID;
     SELECT package_id into cTYPE from A_ID;
     SELECT base_version into cNUMBER from A_ID;
     SELECT description into cDESC from A_ID;
     SELECT new_version into cNEW from A_ID;
     SELECT seq into cSEQUENCE from A_ID;
     --loop that go through history of db updates
          for rec in cur loop
               dID := rec.update_id;
               dTYPE := rec.update_type;
               dNUMBER := rec.patch_number;
               dDESC := rec.description;     
               dOLD := rec.old_db_version;
               --search if patch is already installed, if Yes do nothing, else:
               -- if dID = cID then     
                    --now check version of DB
                    -- if cVER = version then
                                             execute immediate 'begin ' || procedures(1) || ' end;';
          end loop;
          --now check if hotfix can be installed to current version of DB
END;

Similar Messages

  • Normal State Button Shows Selected State At Loop Point

    My menu shows the Normal State Button Shows as the selected state At Loop Point. I want it to show for instance black until it is selected then "rollover" to red. TIA for any help.
    Murman

    There are two ways that you can do this without resorting to using a layer based shape or a layer based menu.
    First, you need to decide if it is important for the logo to appear in full colour or if you can get away with a single colour instance of it appearing. If the answer to this is that a single colour is OK, then use a standard overlay menu. Otehrwise, try using a masked overlay menu (there are limitations...)
    With a standard overlay, the background image is as you want it to appear without anything selected - all shapes and text, etc, should be in place as if no button is chosen.
    You then create the overlay, which is a simple .pict file that is the size of the menu. On this you simply place as many instances of the logo as you need - create them in black or grayscale and don't add anything else. The overlay will be mostly white with the black or gray shapes on it.
    Add this to your menu in DVDSP and drag out the button rectangles to cover the background text and the overlay shape. When the button is selected, the logo shape will show up, but will not show in the normal state.
    You can get the logo to be whatever colour you need by using the colour mapping within the property inspector for the button.
    If you definitley need a full colour logo to appear, you can either use a layer based photoshop menu, or use overlay masks:
    http://www.editorsbin.com/authoring/mask_overlay.html
    be aware that there are some limitations when using the masking technique - but all is explained in that tutorial.

  • Transaction control statements in loop

    for i in p_time_duration_rspm_spm.first..p_time_duration_rspm_spm.last
    loop
    insert into green.solids_aaqm_namp(sample_nr,time_duration_rspm_spm,monometer_reading,
         avg_flow,total_sampling_period,vol_air_sampled,
                             filter_paper_nr,cup_nr)
                   values(p_sample_nr,p_time_duration_rspm_spm(i),
                        p_monometer_reading(i),p_avg_flow(i),
                        p_total_sampling_period(i),p_vol_air_sampled(i),
                        p_filter_paper_nr(i),p_cup_nr(i));
    end loop;
    hallo,
    i am facing a problem in the insert statement.There is a table(3*6).the fields in the table are
    of number datatype.if any character is entered in any of those field a error message as to be
    displayed.
    and if a character is entered into second row, then the readings in the first row is inserted
    in to the table and then a error message is prompted.i want to know whether can we use the transaction control statements
    within the loop to avoid inserting only one row.if so, how?...is there any other way to implement the same at the form level
    before going the database.

    Hello,
    FORALL i in p_time_duration_rspm_spm.first..p_time_duration_rspm_spm.last SAVE EXCEPTIONS
    insert into green.solids_aaqm_namp(sample_nr,time_duration_rspm_spm,monometer_reading,
    avg_flow,total_sampling_period,vol_air_sampled,
    filter_paper_nr,cup_nr)
    values(p_sample_nr,p_time_duration_rspm_spm(i),
    p_monometer_reading(i),p_avg_flow(i),
    p_total_sampling_period(i),p_vol_air_sampled(i),
    p_filter_paper_nr(i),p_cup_nr(i));
    end loop;
    If wants Errors then
    errors := SQL%BULK_EXCEPTIONS.COUNT;
    dbms_output.put_line('Number of DELETE statements that failed: ' || errors);
    FOR i IN 1..errors LOOP
    dbms_output.put_line('Error #' || i || ' occurred during '||
    'iteration #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX);
    dbms_output.put_line('Error message is ' ||
    SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
    END LOOP;
    OR You can use as follows
    for i in p_time_duration_rspm_spm.first..p_time_duration_rspm_spm.last
    loop
    begin -- Newline Added
    insert into green.solids_aaqm_namp(sample_nr,time_duration_rspm_spm,monometer_reading,
    avg_flow,total_sampling_period,vol_air_sampled,
    filter_paper_nr,cup_nr)
    values(p_sample_nr,p_time_duration_rspm_spm(i),
    p_monometer_reading(i),p_avg_flow(i),
    p_total_sampling_period(i),p_vol_air_sampled(i),
    p_filter_paper_nr(i),p_cup_nr(i));
    EXCEPTION when OTHERS then -- Newline Added
    null; -- Newline Added
    end; -- Newline Added
    end loop;
    Bye
    Chitta

  • Insert statement with loop function

    Hello all,
    I'm new with the loop function
    What need to do is to use a select statement with a condition
    This output needs to be inserted in a table
    The values of the condition are stored also in a table
    It will be something like this:
    BEGIN
      FOR i IN (select nrs from table1)  LOOP
        INSERT INTO table_out_loop
        SELECT * FROM bigtable_vw
        WHERE nr = i
      END LOOP ;
    END ;
    I cant use a direct insert_into function in this case so I need the plsql to 'look' for the values 1 by 1 from the table1
    Any help would be appreciated

    Can't you just:
        insert into table_out_loop
        select *
        from   bigtable_vw
        where  nr in (select nrs from table1);
    If not, then post a better example and/or rephrase the question...

  • Re-write provide statement with loop

    Hello,
    I am a bit confused how to rewrite a provide statement but with loop instead.
    For example, how would the following code be written with 'loop at':
    PROVIDE * FROM P0001
              FROM P0016 BETWEEN '20020401' AND '20061001'
    ENDPROVIDE
    Thanks for your help.

    Data Retrieval from LDB
    1. Create data structures for infotypes.
    INFOTYPES: 0001, "ORG ASSIGNMENT
    0002, "PERSONAL DATA
    0008. "BASIC PAY
    2. Fill data structures with the infotype records.
    Start-of-selection.
    GET PERNR.
    End-0f-selection.
    Read Master Data
    Infotype structures (after GET PERNR) are internal tables loaded with data.
    The infotype records (selected within the period) are processed sequentially by the PROVIDE - ENDPROVIDE loop.
    GET PERNR.
    PROVIDE * FROM Pnnnn BETWEEN PN/BEGDA AND PN/ENDDA
    If Pnnnn-XXXX = ' '. write:/ Pnnnn-XXXX. endif.
    ENDPROVIDE.
    Period-Related Data
    All infotype records are time stamped.
    IT0006 (Address infotype)
    01/01/1990 12/31/9999 present
    Which record to be read depends on the date selection period specified on the
    selection screen. PN/BEGDA PN/ENDDA.
    Current Data
    IT0006 Address - 01/01/1990 12/31/9999 present
    RP-PROVIDE-FROM-LAST retrieves the record which is valid in the data selection period.
    For example, pn/begda = '19990931' pn/endda = '99991231'
    IT0006 subtype 1 is resident address
    RP-PROVIDE-FROM-LAST P0006 1 PN/BEGDA PN/ENDDA.
    hope it will be of help to u.

  • Using Looping statements to loop images

    Hi Guys i posted a similar question to this before but i couldn't get anywhere using the method that was described to me. Im currently creating a Puyo Puyo game and im nearly done ive been working on this for about 2 months im still new to java. Anyway my question is, is that after my first two puyo images reach the bottom how would i go about having my next images load and then drop and then have that loop. I understand how to create a loop statement but i just don't understand what parameters i would need to put into it and what kind of loop statement i would need i.e. for loop, do loop etc... I really could use some help ive tried and gotten this far but im pretty stuck. I appreciate any help you can provide. Here is my code so far
    public class Puyo {
        public int x, y, color;
        public Puyo(int c, int x2, int y2) {
            color = c;
            x = x2;
            y = y2;
    import javax.swing.*;
    import java.awt.*; 
    public class DemoTest extends JPanel {
        public static void main(String[] args) { {
        JFrame frame = new JFrame("Puyo Puyo");
        frame.setContentPane(new PuyoAnimation()); 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setSize(200,453);
        frame.setResizable(false);
        frame.setVisible(true);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*; 
    import javax.swing.event.*;
    import java.util.Random;
    public class PuyoLogic extends JPanel {
       public static final int puyoEmpty=0;
      final int board_height = 12;
      final int board_width = 6;
      final int image_height= 32;
      final int image_width = 32;
      final int MAX_X = board_width*image_width;
      final int MAX_Y = board_height*image_height;
      private static final int DELTA_Y = 2;
      private static final int TIMER_DELAY = 20;
      Image images[];
      Puyo puyolist[][];
      Puyo current[];
      Puyo droppingBalls[];
      Timer pptimer;
      Random myRand= new Random();
      boolean keyRight,keyLeft,keyUp;
         public PuyoLogic() {
         super();
            puyolist = new Puyo[board_width][board_height];
            current = new Puyo[2];
            current[0] = new Puyo(myRand.nextInt(4), (board_width * image_width /2), 0);
            current[1] = new Puyo(myRand.nextInt(4), (board_width * image_width /2)+image_width, 0);
        // current[2] = new Puyo(myRand.nextInt(4), (board_width * image_width /2), 0);
       //     current[3] = new Puyo(myRand.nextInt(4), (board_width * image_width /2)+image_width, 0);
         images = new Image[4];
         images[0] = Toolkit.getDefaultToolkit().getImage("puyo_yellow.png");
         images[1] = Toolkit.getDefaultToolkit().getImage("puyo_blue.png");
         images[2] = Toolkit.getDefaultToolkit().getImage("puyo_green.png");
         images[3] = Toolkit.getDefaultToolkit().getImage("puyo_red.png");
         setFocusable(true);
         PuyoMove puyo_move = new PuyoMove(); // Make a new video game KeyListener
         addKeyListener(puyo_move);
         setBackground(Color.BLACK);
          pptimer = new Timer(TIMER_DELAY, new TimerAction());
          pptimer.start();
         public void setAnimation(boolean OnandOff){
            if (OnandOff) {
                pptimer.start(); 
            } else {
                pptimer.stop(); 
        public void NewBlock() {
        int newblock;
        int i,j;
        for(i=0; i<4; i++)
            for(j=0; j<4; j++)
            //puyolist[i][j] = new Puyo[2];
        current[0].x=board_width/2-2;
        current[0].y=0;
        public void puyoBoundsRight(Puyo[] current){
        if ((current[0].x + image_width <= MAX_X - image_width) && (current[1].x + image_width <= MAX_X - image_width)){
        current[0].x += image_width;
        current[1].x += image_width;
        public void puyoBoundsLeft(Puyo[] current){
        if ((current[0].x - image_width >= 0) && (current[1].x - image_width >= 0)){
        current[0].x -= image_width;
        current[1].x -= image_width;
       private class PuyoMove implements KeyListener {
         public void keyTyped(KeyEvent k){}
         public void keyReleased(KeyEvent k){}
         public void keyPressed(KeyEvent k){
            switch (k.getKeyCode()){
             case KeyEvent.VK_LEFT:
                 keyLeft = true;
                 break;
             case KeyEvent.VK_RIGHT:
                 keyRight = true;
                 break;
            public void paintComponent(Graphics g){
            super.paintComponent(g); 
            g.drawImage(images[current[0].color],current[0].x,current[0].y,this);
            g.drawImage(images[current[1].color],current[1].x,current[1].y,this);
           // g.drawImage(images[current[2].color],current[2].x,current[2].y,this);
            //g.drawImage(images[current[3].color],current[3].x,current[3].y,this);
            class TimerAction implements ActionListener {
            public void actionPerformed(ActionEvent e) {
              if (keyLeft){
                puyoBoundsLeft(current);
                keyLeft = false;
              else if (keyRight) { 
                puyoBoundsRight(current);
                keyRight = false;
              if (current[0].y + image_height <= MAX_Y && current[1].y + image_height  <= MAX_Y)
                 current[0].y += DELTA_Y;
                 current[1].y += DELTA_Y;
            else {
                   setAnimation(false);
               repaint();   
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class PuyoAnimation extends JPanel {
       PuyoLogic pl;   
      public PuyoAnimation() {
           pl = new PuyoLogic();       
           JButton startButton = new JButton("Start");       
           JButton stopButton  = new JButton("Stop");
           startButton.addActionListener(new Start());
           stopButton.addActionListener(new Stop());
           JPanel button = new JPanel();
           button.setLayout(new FlowLayout());
            button.add(startButton);
            button.add(stopButton);
           this.setLayout(new BorderLayout());
           this.add(button, BorderLayout.SOUTH);
            this.add(pl,BorderLayout.CENTER);
        class Start implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                pl.setAnimation(true);
        class Stop implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                pl.setAnimation(false);
    }//endclass Edited by: Riz01 on Oct 14, 2009 1:35 PM

    Don't use a loop to do graphics, it will make your game unresponsive and possibly draw enough resources from your machine to make the entire system unresponsive. You make a javax.swing.Timer object and using the timing there to drive your animations.

  • Nested State machine - Loops continuous​ly

    Hello ,
    I implemented a program for first time using state machines and Enum (type def). 
    I have 2 state machines (nested) 
    I am not sure if the data flow between the Main state machine and the Sub state machine is correct. The program loops continuously ( this is a MOTOR PROGRAM) and I see that the motor keeps working continuously. It is supposed to run the mentioned Number of Steps once and then stop.
    Please have a look at my code and tell me where I could have gone wrong. 
    Thank you.
    Abhilash S Nair
    Research Assistant @ Photonic Devices and Systems lab
    [ LabView professional Development System - Version 11.0 - 32-bit ]
    LabView Gear:
    1. NI PXI-7951R & NI 5761
    2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
    OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
    CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
    MEMORY - [ 16.0 GB RAM ]
    GPU - [ NVIDIA GeForce GT 530 ]
    Attachments:
    Motor-UNI_Directiona Dev 1.vi ‏49 KB
    Control 1.ctl ‏6 KB
    Control 2.ctl ‏6 KB

    Figured out ! Thank you. One of the ENUM was not defined to the correct state.
    Thank you. 
    Abhilash S Nair
    Research Assistant @ Photonic Devices and Systems lab
    [ LabView professional Development System - Version 11.0 - 32-bit ]
    LabView Gear:
    1. NI PXI-7951R & NI 5761
    2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
    OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
    CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
    MEMORY - [ 16.0 GB RAM ]
    GPU - [ NVIDIA GeForce GT 530 ]

  • Need help in logic change to avoid select statement inside loop .

    Hello all ,
    Please see the below code . Here i got the shipment number in internal table  IT_VTTK . So For this shipment number i want to get the details from Vekp table in to internal table  IT_VEKP  . There is no need for me to use For all entries . I have passed the value of it_vekp into work area wa_vekp and getting the details in to IT_vekp using loop.
    But since we should not use the select statement inside the loop , Can anybody please tell me how to achieve this functionality .
    Instead of passing into work area wa_vttk if i directly use the internal table I'm getting the following error .
    "IT_VTTK" is a table without a header line and therefore has no component called "TKNUM".
    Hence i have used select statement inside a loop . Please tell me is there any other way to avoid this ?
    types:begin of ty_likp,
            vbeln type likp-vbeln,
           end of ty_likp,
           begin of ty_vttk,
            tknum type vttk-tknum,
            end of ty_vttk.
    DATA: IT_VEKP TYPE STANDARD TABLE OF TY_VEKP,
          WA_VEKP TYPE TY_VEKP.
      data:it_likp type standard table of ty_likp,
           wa_likp type ty_likp,
           it_likp1 type standard table of ty_likp,
           it_vttk type standard table of ty_vttk,
           wa_vttk type ty_vttk.
      data:w_tknum type vttk-tknum.
    if not it_likp is initial .
        select vbeln
                from
                 vbfa
          into table it_vttk
           for all entries in it_likp where vbelv = it_likp-vbeln and vbtyp_n = '8'.
      endif .
    IF IT_VTTK[] IS NOT INiTIAL.
        loop at it_vttk into wa_vttk.
        SELECT venum
               EXIDV
               EXIDV2
               BRGEW
               NTGEW
               GEWEI
               TARAG
               GEWEI
               VHART
               INHALT
             FROM VEKP INTO TABLE IT_VEKP where VPOBJKEY = wa_vttk-tknum  and vpobj = '4'.
          endloop.
          endif.

    Hello,
    Why would you not like to use FOR ALL ENTRIES in the second select? Is it becasue of the length or type mismatch error between the fields VPOBJKEY and wa_vttk-tknum ?
    Vikranth

  • Control statements in  loop s with where cond

    Hi All,
    I am using control statements in the loop which as where condition  , The program works fine but , there is warning message , Is it appropriate to still use .
    Thanks in advance
    Vinay

    below is the code .
    LOOP AT gt_data_table INTO gs_data_table WHERE cust IN s_cust
                                                  AND site IN s_plant
                                                  AND acc_grp = gv_acc_grp
                                                  AND commodity IN s_commd
                                                  AND season IN s_season.
          lv_partial_stk =  lv_partial_stk  +  gs_data_table-available_stk.
          lv_over_stk    =  lv_over_stk     +  gs_data_table-available_stk.
          IF NOT gs_data_table-available_stk IS INITIAL.
            APPEND gs_data_table TO gt_data_table1.
          ENDIF.
          lv_cust       =  gs_data_table-cust.
          lv_commodity  = gs_data_table-commodity.
          lv_season     = gs_data_table-season.
          AT END OF lv_str1 .
            IF gs_data_table-site_typ      = 'COUNTRY'.
              gs_cust_cntry_stk-cust        = gs_data_table-cust .
              gs_cust_cntry_stk-commodity   = gs_data_table-commodity.
              gs_cust_cntry_stk-season      = gs_data_table-season.
              gs_cust_cntry_stk-cntry_stk   = lv_partial_stk.
              APPEND gs_cust_cntry_stk TO gt_cust_cntry_stk.
            ENDIF.
            IF gs_data_table-site_typ     = 'PORT'.
              gs_cust_port_stk-cust       = gs_data_table-cust .
              gs_cust_port_stk-commodity  = gs_data_table-commodity.
              gs_cust_port_stk-season     = gs_data_table-season.
              gs_cust_port_stk-port_stk   = lv_partial_stk.
              APPEND gs_cust_port_stk TO gt_cust_port_stk.
            ENDIF.
            CLEAR lv_partial_stk.
          ENDAT.
          AT END OF lv_str.
            gs_cust_overall_stk-cust         = lv_cust.
            gs_cust_overall_stk-commodity    = lv_commodity.
            gs_cust_overall_stk-season       = lv_season.
            gs_cust_overall_stk-overall_stk  = lv_over_stk .
            CLEAR lv_over_stk.
            APPEND gs_cust_overall_stk TO gt_cust_overall_stk.
          ENDAT.
        ENDLOOP.
    Thanks Guys
    vinay

  • Exception statement for looping query

    Hi this is my query to date:
    declare   
        cursor curs is
         select name_id_no, incident_date
         from MICHAELC.Food_Nov_01_final t
         --where rownum < 6
         for update of cat_latest;
        w_cat_latest        number(4,0);
        w_cat_latest_date   date;
        w_cat_max           number(4,0);
        w_cat_max_date      date;
        w_cat_min           number(4,0);
        w_cat_min_date      date;
    begin
        for i in curs loop
            -- get latest cat date
            select max(cat_score_date) into w_cat_latest_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score_date <= i.incident_date;
            -- get latest cat score
            select cat_score into w_cat_latest
            from rbn_cat
            where customer_no = i.name_id_no
            and cat_score_date = w_cat_latest_date
            and rownum = 1;
            --get maximum cat score
            select max(cat_score) into w_cat_max
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get maximum cat date
            select cat_score_date into w_cat_max_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_max
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            --get minimum cat score
            select min(cat_score) into w_cat_min
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get minimum cat date
            select cat_score_date into w_cat_min_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_min
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            update MICHAELC.Food_Nov_01_final
                set cat_latest = w_cat_latest
                   , cat_latest_date = w_cat_latest_date
                   , cat_max  = w_cat_max
                   , cat_max_date = w_cat_max_date
                   , cat_min    = w_cat_min
                   , cat_min_date = w_cat_min_date
            where current of curs;
        end loop;
    end;
    I receive the following error:
    Error report:
    ORA-01403: no data found
    ORA-06512: at line 37
    01403. 00000 - "no data found"
    *Cause:   
    *Action:
    I want to use an exception statement, something along the lines of
    exception when no_data_found then
                w_cat_latest_date     := NULL;
                w_cat_latest          := NULL;
                w_cat_max             := NULL;
                w_cat_max_date        := NULL;
                w_cat_min             := NULL;
                w_cat_min_date        := NULL;I'm just not really sure how to use the exception statement correctly and if it is the best way to handle this error. Thank-you for your time and help.
    Banner:
    Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE 11.2.0.2.0 Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    Like this;-
    declare   
        cursor curs is
         select name_id_no, incident_date
         from MICHAELC.Food_Nov_01_final t
         --where rownum < 6
         for update of cat_latest;
        w_cat_latest        number(4,0);
        w_cat_latest_date   date;
        w_cat_max           number(4,0);
        w_cat_max_date      date;
        w_cat_min           number(4,0);
        w_cat_min_date      date;
    begin
        for i in curs loop
            -- get latest cat date
    BEGIN
            select max(cat_score_date) into w_cat_latest_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score_date <= i.incident_date;
    EXCEPTION
    when no_data_found then
                w_cat_latest_date     := NULL;
    END;       
    BEGIN
            -- get latest cat score
            select cat_score into w_cat_latest
            from rbn_cat
            where customer_no = i.name_id_no
            and cat_score_date = w_cat_latest_date
            and rownum = 1;
    EXCEPTION
    when no_data_found then
                w_cat_latest
         w_cat_latest:= NULL;
    END;       
    /*   you get the idea
            --get maximum cat score
            select max(cat_score) into w_cat_max
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get maximum cat date
            select cat_score_date into w_cat_max_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_max
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            --get minimum cat score
            select min(cat_score) into w_cat_min
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get minimum cat date
            select cat_score_date into w_cat_min_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_min
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            update MICHAELC.Food_Nov_01_final
                set cat_latest = w_cat_latest
                   , cat_latest_date = w_cat_latest_date
                   , cat_max  = w_cat_max
                   , cat_max_date = w_cat_max_date
                   , cat_min    = w_cat_min
                   , cat_min_date = w_cat_min_date
            where current of curs;
        end loop;
    end;
    /

  • SQL statement in loop

    Hi,
    I have a requirment where in i will have to insert some records 100 times and one of the inserted values should be a unique number and the rest of the values are same like
    insert into table (col1, col2, col3) values(X, 1000,sysdate);
    where the value of x should be from 1 to 100 for each insert.
    I would appreciate if some one could tell me how to write using a loop.
    Thanks

    Create a sequence
    CREATE SEQUENCE my_sequence_nameand then use the sequence in the loop
    INSERT INTO table_name( col1, col2, col3 )
      VALUES( my_sequence_name.nextval, 1000, sysdate );Of course, it would be better if you inserted 100 rows in a single INSERT rather than using a loop in the first place.
    Justin

  • Collect statement  in Loop..

    Hi,
    I have an Internal table ITAB  with following records.
    REC1         10    
    REC1         20     
    REC2         15
    REC2         25
    REC2         35
    and I need an output
    REC1        30
    REC2        75
    I tried like this
    LOOP AT ITAB.
    COLLECT ITAB.
    MODIFY ITAB.
    ENDLOOP.
    Am i doing something wrong?? I am still getting 5 records in output..
    regards
    Praveen

    Hi Praveen,
    You create another internal table with te same table type.
    Then you write collect on the internal table.
    define Itab1 like itab. and write logic like below.
    LOOP AT ITAB.
    ITAB1 = ITAB.
    COLLECT ITAB1.
    ENDLOOP.
    Thanks,
    Ramakrishna

  • SQL Statement as Loop - easy question?

    Am reading from S. Feuerstein's book:
    DECLARE
    CURSOR checked_out_cur IS
    SELECT pet_id, name, checkout_date
    FROM occupancy WHERE checkout_date IS NOT NULL;
    BEGIN
    FOR checked_out_rec IN checked_out_cur
    LOOP
    INSERT INTO occupancy_history (pet_id, name, checkout_date)
    VALUES (checked_out_rec.pet_id, checked_out_rec.name, checked_out_rec.checkout_date);
    My question is - where did checked_out_rec came from? Doesn't look like it's declared.
    Thanks,

    http://www.unix.org.ua/orelly/oracle/prog2/ch07_07.htm
    In fact the very next section begins,
    "This will work just fine. But do we really need to use a cursor FOR loop to accomplish this task?"
    (I think the above is from an earlier edition of the book, but later editions make the same point.)
    If you flip back a couple of pages there is whole section on the convenience of the implicit record declaration, along with the implicit open, fetch and close.

  • Problems closing several loops in a state machine with an event structure

    I am having some problems closing three loops running in parallel in a state machine.  I have one loop for an event structure to monitor user controls to change the state.  The other loop is the state machine which will control an actuator, and the third loop is for data aquisition/analysis.  I want to be able to hit the stop button and go to a "shutdown" state where I can home the actuator then close the loops and finally go to the last "shutdown" subdiagriam in the flat sequence structure.  Currently when hitting the stop button it goes into the shutdown state and will end the state machine loop but it appears the other loops are not closing until I hit the stop button again.  Could this be due to using a local variable for the boolean to control the loop conditions? I attached a screenshot of the block diagram.  Any advice would be great!
    Attachments:
    example.png ‏108 KB

    You have a classic race condition due to overuse of local variables. If the stop event fires in the upper loop, the local variable connected to the loop termination condition has already been read (it is false!). This means that the upper loop will iterate once more and again wait at the event structure for the next event. At this time, the local variable connected to the loop termination is TRUE, but the loop cannot complete until the event fires again, for example if you press the stop button once more.
    The correct way is to connect the terminal of the stop button across the right event frame directly to the loop termination terminal. Now it will get the TRUE value correctly once the stop event fires for the first time.
    LabVIEW does not execute left to right, execution order is determined by the wiring.
    I also agree with the above message that you should rethink and re-architect your code using established coding guidelines. 
    LabVIEW Champion . Do more with less code and in less time .

  • Nested Loops...looping through one month of data at a time year by year

    Hi all,
    I'm trying to create an insert statement that loops through a table that has 10 years of data (2001 to 2010) month by month to minimize impact on server and commits more frequently to avoid filling up the redo logs and rollback tablespaces. The table is large, has about 40 millions records per year. Lets say the structure of the table is the following:
    Customer_ID number(9),
    Order_Item_1 number(6),
    Order_Item_2 number(6),
    Order_Item_3 number(6),
    Order_date date
    The table is in flat format but I want to normalize it so that it looks like the following:
    Customer_ID Order_Seq Order_Item Order_date
    999999999 1 555555 01-jan-2001
    999999999 2 666666 01-jan-2001
    999999999 3 444444 01-jan-2001
    888888888 1 555555 03-jan-2001
    888888888 2 666666 03-jan-2001
    But because I want to loop through month by month....I need to set it up so that it loops through month by month, year by year (Using the Order Date Field) and Order_item by Order_item. Something like:
    so my insert statements would be something like if I hardcoded instead of put the insert statement into a loop:
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,1,Order_item,Order_date where Order_item_1 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,2,Order_item,Order_date where Order_item_2 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,3,Order_item,Order_date where Order_item_3 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,1,Order_item,Order_date where Order_item_1 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='02';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,2,Order_item,Order_date where Order_item_2 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='02';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,3,Order_item,Order_date where Order_item_3 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='03';
    Hope this makes sense.
    Thanks

    Does the sequence of items in an order really matter? In other words, do we really need to preserve that an item was in position 2 versus position 1? I bet that the sequence or position of each item in an order is not meaningful. They were probably numbered 1, 2, and 3 just to make them uniquely named columns so there would be three slots to hold up to 3 items in the denormalized table.
    You only have about 400 million rows to insert, so it could feasibly be done in a single transaction (depending on your database environment).
    You can always do a create table as select (CTAS) to help with undo / redo issues and get better performance. You could run it in parallel, and spit it out to a new table partitioned by month. Single DDL statement running in parallel making your new table--sounds good to me.
    How about something like this:
    CREATE TABLE ORDERS_NORMALIZED
    (CUSTOMER_ID, ORDER_ITEM, ORDER_DATE)
    PARTITION BY RANGE(ORDER_DATE)
    PARTITION p200901 VALUES LESS THAN (TO_DATE('200902','YYYYMM')),
    PARTITION p200902 VALUES LESS THAN (TO_DATE('200903','YYYYMM')),
    PARTITION p201012 VALUES LESS THAN (TO_DATE('201101','YYYYMM'))
    as SELECT CUSTOMER_ID, ORDER_ITEM_1, ORDER_DATE
       FROM OTHER_TABLE
       WHERE ORDER_ITEM_1 IS NOT NULL
       UNION ALL
       SELECT CUSTOMER_ID, ORDER_ITEM_2, ORDER_DATE
       FROM OTHER_TABLE
       WHERE ORDER_ITEM_2 IS NOT NULL
       UNION ALL
       SELECT CUSTOMER_ID, ORDER_ITEM_3, ORDER_DATE
       FROM OTHER_TABLE
       WHERE ORDER_ITEM_3 IS NOT NULL.....................
    Out of curiosity, why not normalize it further? You could have used two tables instead of one.
    One (ORDER) with:
    ORDER_ID
    CUSTOMER_ID
    DATE
    Order_id would be a new surrogate key / primary key.
    Another table (ORDER_ITEM) with:
    ORDER_ID
    ORDER_ITEM
    It would be a table that links ORDERS to ITEMS. You get the idea.

Maybe you are looking for