Control Statment in PL/SQL Basic Loop

Hi,
I have a PL/SQL procedure which contains a basic loop. Please refer the below sample code. In the following code, I just process each record. I would like to skip a record process if certain condition arrives. Right now My code it goes to exception block if exception is arrived during a particular record process. I should not allow control to go to exception block i.e. If condition is failed, it should go to beginning of the code.
I know that I could use GOTO <label> statement to go back to beginning of the loop to process next record.
My question is
Is there any other way to continue the loop if I need to skip a record rather than using GOTO statement. I know that we can use CONTININUE statement in programming language like C, COBOL. !!. I need the best practice code in this case. Please suggest me.
Actual Code:
Loop
Begin
<< if record process failed here ..control goes to Exception block..
Exception
End Loop
My code using GOTO statement to cotinue the loop
Loop
Begin
<Loop_Begin>>
<< if record process failed here >>
GOTO <Loop_Begin>> /* Control never go to Exception block */
Exception
End Loop
Regards,
Thambi

Hi,
Thanks for the reply. I need to skip entire process , my code has aleady some statments after 'If-Endif' condition. Null statment does nothing.. it just skip the line and execute from the next statment. I have lot of statments before and after IF-END-IF condition. I don't want to execute next statment .. want to go to begining of the loop
loop
begin..
if ( )
skip and should go to begining of the loop.
end if
<< i have some statment here >>
Exception
End loop

Similar Messages

  • Using a form control (textbox) as an SQL Server parameter

    Hi
    i am trying to use a form textbox control to filter an SQL query but i do not know how to do this. In fairness, im from an Access background originally and can easily do it in Access lol.
    Is it better to connect to the SQL database using code and create an SQL string to get / set data? if so? how can i do that?
    or
    do i use a table adapter which is my current method but i do not know how to integrate a text control as a query parameter.
    for reference-
    Query = SQL Server View (Same as access Database Query)
    Thanks for any help
    Nigel
    Nacho is the derivative of Nigel "True fact!"

    Hi nmjShaw,
    I wrote a sample about how to integrate a text control as query parameter in vb.net.
    Dim conn As New System.Data.OleDb.OleDbConnection()
    conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database2.accdb"
    Try
    Dim sql As String = "SELECT * FROM tbl_user WHERE username = @username"
    Dim dt As New DataTable()
    Dim sqlCom As New System.Data.OleDb.OleDbCommand(Sql, conn)
    'Open Database Connection
    sqlCom.Parameters.AddWithValue("@username", TxtControl.Text)'integrate text control as parameter here
    sqlCom.Connection = conn
    conn.Open()
    Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, conn)
    da.Fill(dt)
    ' Then you could use the dt.
    conn.Close()
    Catch ex As Exception
    MessageBox.Show("Error:" & ex.Message)
    End Try
    If you have any other concern regarding this issue, please feel free to let me know.
    Best regards,
    Youjun Tang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Control file for the sql*loader

    hi
    i'm doing my project in database management as the part of my project i have to write the control file for the sql*loader so, any one please clear the funda...so that i can get back to my project work...help me with sample code ..

    Refer chapter 3 and 5 on this url for sql loader and its control file references :
    http://download-west.oracle.com/docs/cd/A91202_01/901_doc/server.901/a90192/toc.htm
    or
    http://download-east.oracle.com/docs/cd/A91202_01/901_doc/server.901/a90192/toc.htm
    You may also refer sql loader examples on this page:
    http://otn.oracle.com/sample_code/products/intermedia/htdocs/avi_bulk_loading.html
    Chandar

  • Executing ddl statment in pl/sql block

    Hi all,
    could anyone pls help in method for executing ddl statment in pl/sql block other than 'execute immediate' ?

    could anyone pls help in method for executing ddl statment in pl/sql block other than 'execute immediate' ?On newer db versions you have more options:
    SQL> desc t
    Error: object t does not exist
    SQL> exec sys.dbms_prvtaqim.execute_stmt('create table michael.t (a integer)')
    PL/SQL procedure successfully completed.
    SQL> desc t
    TABLE t
    Name                                      Null?    Type                       
    A                                                  NUMBER                     
    SQL> exec sys.dbms_utility.exec_ddl_statement('drop table michael.t')
    PL/SQL procedure successfully completed.
    SQL> desc t
    Error: object t does not exist;)

  • Very basic loop question

    Hi everyone, I&acute;m somewhat new with programming and I have a very basic loop problem, that I can&acute;t solve.
    I have 3 ArrayLists:
    A has the project information, ordered by client, identified by a projectId, clientId and businessId
    B has the client information, ordered by business, identified by a clientId and businessId
    C has the business information, identified by a businessId.
    I need to show all the projects of a client, then the client information of a certain business, and at last the business information in a format like this:
    A -- Project1
    A -- Project2
    A -- Project3
    B -- Client1
    A -- Project4
    A -- Project 5
    A -- Project 6
    B -- Client2
    C -- Business1
    A -- Project7
    A -- Project8
    B -- Client3
    A -- Project9
    B -- Client4
    C -- Business2
    How should I program my loops? I've been trying different ways but everytime it doesn't print what I want. Help, please!

    OK, here's my code:
    for(int bussCounter= 0; bussCounter< bussArray.size(); bussCounter++)
       ValueObject bussVO = bussArray.get(bussCounter);
       String bussId = bussVO.getBussId();
       for (int clieCounter = 0; clieCounter < clieArray.size(); clieCounter++)
          ValueObject clieVO = clieArray.get(clieCounter);
          String clieId = clieVO.getClieId();
          String bussIdClie = clieVO.getBussId();
             for (int projCounter = 0; projCounter < projArray.size(); projCounter++)
                ValueObject projVO = projArray.get(projCounter );
                String clieIdProj = projVO .getClieId();
                String bussIdProy = projVO .getBussd();
                if (clieIdProy == clieId && bussIdProy == BussIdClie)
                   out.println("<tr>");
                   out.println("<td>" + projVO .getBussId() + "</td>");
                   out.println("<td>" + projVO .getClieId() + "</td>");
                   out.println("<td>" + projVO .getProjId() + "</td>");
                  out.println("<td>" + projVO .getTotal() + "</td>");
                  out.println("</tr>");
              if (bussIdClie == bussId)
                 out.println("<tr>");
                 out.println("<td>" + clieVO .getBussId() + "</td>");
                 out.println("<td>" + clieVO .getClieId() + "</td>");
                 out.println("<td>" + clieVO .getTotal() + "</td>");
                 out.println("</tr>");
       out.println("<tr>");
       out.println("<td>" + bussVO .getBussId() + "</td>");
       out.println("<td>" + projVO .getTotal() + "</td>");
       out.println("</tr>");
    }

  • Basic loop error ....

    here m entering numbers from 1 to 10 ..excluding 6 & 8 ...with the help of Basic loop ...but it's not executing ....only ...it's goes into the end now state ......
    so plz .help me with the correct code .....

    --create table messages (results number(4))
    DECLARE
         v_counter number(4) := 1;
    BEGIN
    LOOP
         IF v_counter = 6 OR v_counter = 8
         THEN null;
         ELSE
         INSERT into messages(results)
         VALUES(v_counter);     
         v_counter := v_counter + 1;      
         EXIT WHEN v_counter = 10;
    END IF;
    END LOOP;
    END;
    DECLARE
    v_counter number(4) := 1;
    BEGIN
    LOOP
    IF v_counter = 6 OR v_counter = 8
    THEN
    null;
    ELSE
    INSERT into messages(results)
    VALUES(v_counter);
    v_counter := v_counter + 1;
    END IF;
         EXIT WHEN v_counter = 10;
    END LOOP;
    END;
    Here is the CODE ....

  • Error in insert statment in pl/sql

    Hi all,
    How i Execute Insert statment in Pl/Sql
    SQL> DECLARE
    2 tablename varchar2(30);
    3 Begin
    4 begin
    5 select table_name into tablename from user_tables
    6 where table_name=upper('t_calling');
    7 EXCEPTION
    8 WHEN no_data_found then
    9 execute immediate 'create table t_calling(F_CODE number,
    10 F_CALLING varchar2(50))';
    11 INSERT INTO T_Calling VALUES (1, 'asd');
    12 end;
    13 -- --------------------------
    14 Commit;
    15 End;
    16 /
    INSERT INTO T_Calling VALUES (1, 'asd');
    ORA-06550:
    PLS-00201: identifier 'T_CALLING' must be declared
    ORA-06550:
    PL/SQL: SQL Statement ignored
    Thanks
    alaa

    You are creating this table with an execute immediate statement. Which suggests that it doesn't exist yet. Therefore your insert statement is referencing a non-existent table so naturally it won't compile.
    If you really want to do this you should put the insert into an execute immediate statement as well. However, I recommend that you don't do this - it is very bad practice to put this sort of processing in the exception handler. Why? Well, what happens if the table T_CALLING already exists? The exception's got no where to go, so your program fails with an Unhandled Exception error.
    HTH, APC

  • Pl/sql vs sql basic question

    Hi,
    I have a very very basic question, so excuse me for that... I just would like to know the difference ( and the difference in usage) between sql and pl/sql?
    thank you
    Yann

    SQL - the structured query language - is the language available for extracting data from the database. It is a 4GL, and each command stands alone and performs a database action.
    PL/SQL is the 3GL primarily intended to control the flow of a series of SQL commands. PL/SQL does not, in any way, interact with the data in the database. It does, however, allow SQL statements to be called, or even created, in a specific order.
    SQL is capable of a LOT more than people usually realize. Unfortunate, as people often create PL/SQL programs when single SQL statements will do the job. I encourage reading the O'Reilly 'Mastering Oracle SQL' book ... only after fiunishing that book do I recommend any of Feuerstein's excellent PL/SQL books.

  • Doubts with control break statements on internal table loops (AT/ENDAT)

    Hi, i've had a couple of doubts for a long while which I hope someone can clarify today:
    1) I know how to use the AT statements, however, i'm not sure I get correctly what this part of help regarding this commands means:
    <i>"The control level structure with internal tables is static. It corresponds exactly to the sequence of columns in the internal table (from left to right). In this context, the criteria according to which you sort the internal table are unimportant."</i>
    I've always sorted the internal table before the control break and it works that way. For example:
    SORT ITAB BY EBELN EBELP.
    LOOP AT ITAB.
      AT NEW EBELN.
    *   Code for the order header
      ENDAT.
    ENDLOOP.
    If I <b>don't</b> sort the internal table, it doesn't work! (i get dupplicated processing). In the example, if i have more than one register with the same EBELN and they're not consecutive, the header gets processed twice. I really don't get that part of the help text.
    2) I know this: <i>"At the start of a new control level (i.e. immediately after AT), the following occurs in the output area of the current LOOP statement:
    All character type fields (on the right) are filled with "*" after the current control level key.
    All other fields (on the right) are set to their initial values after the current control level key."</i>
    My doubt is: WHY is that this way? Because sometimes (most times) I need those fields INSIDE the statement! So when that happened i've solved it in one of three ways:
    LOOP AT ITAB INTO WA_ITAB.
      WA_ITAB_AUX = WA_ITAB.
      AT NEW FIELD.
        WA_ITAB = WA_ITAB_AUX.
    *   ...Rest of the code for the first register
      ENDAT.
    ENDLOOP.
    LOOP AT ITAB INTO WA_ITAB.
      AT NEW FIELD.
        READ TABLE ITAB INDEX SY-TABIX INTO WA_ITAB.
    *   ...Rest of the code for the first register
      ENDAT.
    ENDLOOP.
    * (Without AT)
    LOOP AT ITAB INTO WA_ITAB.
      IF WA_ITAB-FIELD <> FIELD_AUX.
        FIELD_AUX = WA_ITAB_FIELD.
    *   ...Rest of the code for the first register
      ENDIF.
    ENDLOOP.
    Is there any problem with this way of coding? Can be done better?
    Thank you very much in advance.

    Hi..,
    1)
    See if u sort the table on a field on which u r using AT ENDAT .. then all the records which are having the same value for that field will form a group or those reocrds will be at one place.. so when u sort the table for all the records  AT ENDAT  will get executed onli once..
    If u dont sort this table on this field then all these records will be at different places and in between there may be records with different value for this field.. so this AT ENDAT will get executed for each record !!
    2)
    No u cannot use the Right hand fields of the field in the table .. Because these AT events work as Group based operations... So till that field on which AT ENDAT is working it breaks that record into two groups.. One is the left hand fields including that field.. and right hand fields as another group.. and makes the right hand group as stars ****.  Thats y u can observe that even any one field in the left hand group changes the AT ENDAT will get executed  !!!!
    Hope u understood !!!
    regards,
    sai ramesh

  • Is there any way to use Control Break in a SQL Query

    Hi,
    Is there any way to use a control break on Dept column in a SQL query to have a Output-2 instead of Output-1.
    Is there any way to modify the SQL query.
    SQL
    select dept, loc, count(*)
      from dept
    group by dept, locOutput-1
      Dept      Loc       Count(*)
      10         AA        1
      10         BB        2
      10         CC        2
      20         AA        2
      20         BB        2Output-2
      Dept      Loc       Count(*)
      10         AA        1
                 BB        2
                 CC        2
      20         AA        2
                 BB        2Thanks,
    Deepak

    DeepakJ wrote:
    Hi,
    Is there any way to use a control break on Dept column in a SQL query to have a Output-2 instead of Output-1.
    Is there any way to modify the SQL query.
    SQL
    select dept, loc, count(*)
    from dept
    group by dept, locOutput-1
    Dept      Loc       Count(*)
    10         AA        1
    10         BB        2
    10         CC        2
    20         AA        2
    20         BB        2Output-2
    Dept      Loc       Count(*)
    10         AA        1
    BB        2
    CC        2
    20         AA        2
    BB        2
    Yes, using the <tt>lag</tt> analytic function and specified ordering of the data:
    select
        nullif(d.deptno, lag(d.deptno) over (order by d.deptno, d.loc, e.mgr nulls first)) deptno
      , nullif(d.loc, lag(d.loc) over (order by d.deptno, d.loc, e.mgr nulls first)) loc
      , e.mgr
      , count(*) n
    from
        dept d
          join emp e
            on d.deptno = e.deptno
    group by
        d.deptno
      , d.loc
      , e.mgr
    order by
        d.deptno
      , d.loc
      , e.mgr nulls first;
    DEPTNO  LOC       MGR   N
        10  NEW YORK         1
                      7782   1
                      7839   1
        20  DALLAS    7566   2
                      7788   1
                      7839   1
        30  CHICAGO   7698   4
                      7839   1
        40  BOSTON    7698   2
                      7902   1

  • PL/SQL cursor loop...error  INTO clause needed...but multiple rows

    Oracle 11gR2 Linux x86_64
    Hi all,
    I am running the below PL/SQL block but getting the below error. From what I know, the INTO clause can only be used when a single row will be returned. In this case, I know it returns multiple rows, so why is it asking to use the INTO clause?
    DECLARE
      v_object VARCHAR2(10) := 'TABLE';
      v_schema VARCHAR2(30) := 'TEST';
    CURSOR tblsze_cur IS
        SELECT table_name
        FROM dba_tables
        WHERE owner='TEST'
        AND table_name IN (
        'T1',
        'T2',
        'T3');
    BEGIN
    FOR tbl_rec IN tblsze_cur
        LOOP
            select * from
            table(dbms_space.OBJECT_GROWTH_TREND
            (v_schema,tbl_rec.table_name,v_object));
        END LOOP;
    END;
    select * from table(dbms_space.OBJECT_GROWTH_TREND
    ERROR at line 21:
    ORA-06550: line 21, column 3:
    PLS-00428: an INTO clause is expected in this SELECT statement

    Ok, I think I have the TYPES correct...taken from the documentation.
    DECLARE
      v_object VARCHAR2(10) := 'TABLE';
      v_schema VARCHAR2(30) := 'TEST';
      TYPE object_growth_trend_row IS RECORD(
        timepoint      TIMESTAMP,
        space_usage    NUMBER,
        space_alloc    NUMBER,
        quality        VARCHAR(20));
      TYPE object_growth_trend_table IS TABLE OF object_growth_trend_row;
      TYPE nmtbl IS TABLE OF dba_tables.table_name%TYPE;
      tname nmtbl;
    CURSOR c1 IS
        SELECT table_name
        FROM dba_tables
        WHERE owner='TEST'
        AND table_name IN (
        'T1',
        'T2',
        'T3');
    BEGIN
    OPEN c1;
    FETCH c1 BULK COLLECT INTO tname;
    FOR i IN tname.FIRST .. tname.LAST
        LOOP
             select * from (dbms_space.OBJECT_GROWTH_TREND (v_schema, tname, v_object)) INTO object_growth_trend_table;
             DBMS_OUTPUT.PUT_LINE (object_growth_trend_table);
        END LOOP;
    CLOSE c1;
    END;
    select * from (dbms_space.OBJECT_GROWTH_TREND (v_schema,tname,v_object) INTO object_growth_trend_table);
    ERROR at line 33:
    ORA-06550: line 33, column 55:
    PL/SQL: ORA-00907: missing right parenthesis
    ORA-06550: line 33, column 9:
    PL/SQL: SQL Statement ignored

  • Time-out error due to SQL in loop

    Hi Folks,
    Have an issue with performance. I have a couple of scenarios:
    1) A custom report program loops through 9000 odd records (records which are being fetched from BSEG, BSID table). It gives a short dumpafter 10 mins. It is a TIME_OUT error. The maximum runtime profile parameter rdisp/max_wprun_time is set to 600 seconds and thus its apparently obvious that the program will dump as a result. The code has a few few selects inside the LOOP which may be the reason.
    2) The same program loops through 22000 odd records for a different set of data in the selection screen and gives the output (ALV Display) after 2 hours!!
    I am now not sure why is it behaving differently by not giving a short dump in the second case.
    Will be very thankful to however is able to provide me any lead for this issue.
    Thanks and Regards,
    Shashank.

    Hi,
    Don't spend your time to  imagine what is you exact problem in your program trace your program which database sql take longer time useing the ST05 try to avoid the bulk data read in loop if possible.
    You mention in point 1 it is correct.
    Why you are reading all data at all ?
    Just read some chunk of data and process (ie. read maximum of 50-50 record and process).
    Suppose if you are reading 10,000 record at a time it will take approximate 15 minutes to execute the SQL such snario it will give dump due to maximum execution time is 10 minutes. gives timeout  runtime error. Read 50 or 100 record at a time then process set of record and read again. you can also used the the pakage.

  • Tyring to dynamically create SQL statment for an SQL Calendar

    Is there a way to dynamically create an SQL statement that an SQL Calendar would use. I don't see an option to create a PL/SQL Calendar.
    For example I want to pass a table name, and the corresponding date column to items on the calendar page, and then have the SQL Calendar use those to fields to display the number of records loaded into the specified table. I've written the following but it doesn't work:
    'SELECT count(*), ' || :P8_SOURCE_DATE || ' FROM ' || :P8_SOURCE_TABLE || ' GROUP BY ' || :P8_SOURCE_DATE;
    Does anyone know if there is a why to create a PL/SQL Calendar?

    Jason,
    it is possible, though not so simple as with a report.
    What you need to do is to create a pipelined function, that returns your date and count data. This pipelined function can be the base of a pseudo-table, which can be used in a select. For the pipelined function you need to define types for one row and a table to define the return-type for your function:
    create or replace type calendar_row as object (date_time date, description varchar2(250));
    create type calendar_table as table of calendar_row;
    Then you can create the package with the function:
    ================================================
    create or replace package dyn_calendar is
    procedure set_query(i_query in varchar2);
    function view_source return calendar_table pipelined;
    end;
    create or replace package body dyn_calendar is
    v_query varchar2(100) := null;
    procedure set_query(i_query in varchar2) is
    begin
    v_query := i_query;
    end;
    function view_source return calendar_table pipelined is
    TYPE cursor IS REF CURSOR;
    c_cal cursor;
    v_date_time date := null;
    v_description varchar2(100) := null;
    r_cal calendar_row;
    begin
    open c_cal for v_query;
    fetch c_cal into v_date_time, v_description;
    loop
    exit when c_cal%notfound;
    r_cal := calendar_row(v_date_time, v_description);
    pipe row(r_cal);
    fetch c_cal into v_date_time, v_description;
    end loop;
    return;
    end;
    end;
    ================================================
    Now you can set query in a PL/SL region before the calendar:
    dyn_calendar.set_query(SELECT count(*), ' || :P8_SOURCE_DATE || ' FROM ' || :P8_SOURCE_TABLE || ' GROUP BY ' || :P8_SOURCE_DATE);
    and you can base your calendar on the query:
    select * from table(dyn_calendar(view_source))
    Good luck,
    Dik

  • Point/Migrate batch jobs from Sybase(auto scheduled through Control-M application) to SQL Server 2005

    Hi,
    I am currently working in project where we need to migrate/point batch jobs to SQL server 2005. At this moment they are pointing to Sybase. Batch jobs are in .bat and .exe format. These jobs read in an external file, does some reformatting,
    and then loads it into 2 sybase tables. These jobs are auto scheduled through Control-M application.
    Any idea please ?
    Thanks,
    Chirag Patel

    Change your post to type 'Question' Chirag
    You would need to at least change the connection strings, and how you access SQL Server, but typically code changes are necessary.
    You unfortunately don't provide enough details. But it is not as trivial to just 'point' a bunch of jobs to a new target.
    Arthur My Blog

  • How to control DC motor in a simulation loop??

    Hi,
    I am Xiaofei, a beginner of LV. We plan to use feedback control on 2 DC motors using Simulation loop. Now the question is: i am not quite sure if the simulation loop is only a virtual simulation of the system, or it can be used to control the real system. We will use 2 encoders to detect the actual postion of the motor shafts, and the decoding code works well in a while loop, as the attached VI. But we don't know how to make it work in a simulation loop. Whenever we put it in a simulation loop and click "run", there's no response  no matter what we do on the system. So if you know, could you tell me if the simulation loop is suitable for our application and what we can do to run the encoders in it? Thanks a million!! 
    Xiaofei

    Hi Xiaofei,
    Thanks for posting on the NI forums!  Can you tell me a little more about your setup?  What do you mean by Simulation loop?  Do you mean Simulation Module or Simulation Interface Toolkit?  What hardware are you using to control the motors and read the encoder feedback?  What kind of motors do you have?  Can you read the encoder inputs in LabVIEW when you turn the motors by hand?
    Thanks,
    Maclean G.
    National Instruments
    Applications Engineer

Maybe you are looking for