Raise the Exception in loop For

Currently my loop code is
FOR i IN 2..vt_records.count
        LOOP
          EXIT WHEN INSTR(vt_records(i), v_delimiter,2) = 0;
            csv_to_array(vt_records(i), vt_record, v_delimiter);

          --| Workaround for the case when the last column is null
          IF vt_record.count < v_expected_csv_cols
            THEN
              FOR i IN 1..(v_expected_csv_cols - vt_record.COUNT)
                LOOP
                  --RAISE_APPLICATION_ERROR(-20000, 'vt_Record.COUNT=' || vt_record.count || ' - loopcount=' || (v_expected_csv_cols-vt_record.COUNT));
                  vt_record(vt_record.COUNT+1) := NULL;
                END LOOP;
          END IF;

         begin
         --{
           INSERT INTO cit_interface_correlation (
           massupdateid,
           primarymatkey_hr,
           geokey_hr,
           depmatkey_hr,
           promokey_hr,
           statcalcday,
           usercorfactor,
           inst_user,
           inst_session,
           inst_date
           ) 
           VALUES
           (
           seq_cit_interface_correlation.nextval,
           vt_record(1),
           TRIM(vt_record(2)),
           TRIM(vt_record(3)),
           vt_record(4),
           TO_DATE(TRIM(vt_record(5)),'DD.MM.YYYY'),
           TRIM(vt_record(6)),
           v('APP_USER'),
           v('APP_SESSION'),
           sysdate
           );
         --}
         end;
      END LOOP;
{code]
What I need to do is raise an exception if vt_record(5) is greater than sysdate.
If any line has a date greater than sysdate then the loop should fail and not carry on.

Cheers

Gus                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

Like this?

for i in 2..vt_records.count
loop
     exit when instr(vt_records(i), v_delimiter,2) = 0;

     csv_to_array(vt_records(i), vt_record, v_delimiter);

     if vt_record.count < v_expected_csv_cols
     then
          for i in 1..(v_expected_csv_cols - vt_record.count)
          loop
               vt_record(vt_record.count+1) := null;
          end loop;
     end if;

     if vt_record(5) > sysdate then
          raise_application_error(-20001, 'vt_record(5) is greater than sysdate');
     else
          insert into cit_interface_correlation
          (
               massupdateid,
               primarymatkey_hr,
               geokey_hr,
               depmatkey_hr,
               promokey_hr,
               statcalcday,
               usercorfactor,
               inst_user,
               inst_session,
               inst_date
          )
          values
          (
               seq_cit_interface_correlation.nextval,
               vt_record(1),
               trim(vt_record(2)),
               trim(vt_record(3)),
               vt_record(4),
               to_date(trim(vt_record(5)),'dd.mm.yyyy'),
               trim(vt_record(6)),
               v('APP_USER'),
               v('APP_SESSION'),
               sysdate
          );
     end if;
end loop;

Tags: Database

Similar Questions

  • 10g: re-raise the exception modifies the call stack

    Hello! I'm "Oracle PL/SQL Reference" and trying to re-raise the exception:
    begin
      dbms_output.put_line('line a');
      raise no_data_found;
    exception
      when others then
          dbms_output.put_line('line b');
          raise;
    end;
    Oracle reports exception was thrown on line 7, not 3. Apparently "re-raise" modifies the call stack, making it of no use: I can throw a new exception with the same success. It is not re - raise a conventional sense of the term. The question is, is there a possibility to actually STILL raise exception, without changing the call stack?

    A reference to 'Lines followed by Steven Feuerstein'

    Impact of multiple reminders

    Often, an exception occurs at the bottom of the execution stack. If you want this exception to propagate all the way to the PL/SQL block outside, it should be re-relief within each exception handler in the stack of blocks. Listing 3 shows an example of such an event.

    Code Listing 3: Re-raising exceptions to the outermost block on the stack

    CREATE OR REPLACE PROCEDURE proc1 IS
    BEGIN
       DBMS_OUTPUT.put_line ('running proc1');
       RAISE NO_DATA_FOUND;
    EXCEPTION
       WHEN OTHERS THEN
          DBMS_OUTPUT.put_line (
             'Error stack in block where raised:');
          my_putline (
             DBMS_UTILITY.format_error_backtrace);
          RAISE;
    END;
    /
    CREATE OR REPLACE PROCEDURE proc2
    IS
       l_str VARCHAR2 (30) := 'calling proc1';
    BEGIN
       DBMS_OUTPUT.put_line (l_str);
       proc1;
    END;
    /
    CREATE OR REPLACE PROCEDURE proc3 IS
    BEGIN
       DBMS_OUTPUT.put_line ('calling proc2');
       proc2;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line ('Error stack at top level:');
          my_putline (DBMS_UTILITY.format_error_backtrace);
          bt.show_info (DBMS_UTILITY.format_error_backtrace);
    END;
    /
    

    When I run the code in Listing 3, I see the following result:

    SQL> exec proc3
    calling proc2
    calling proc1
    running proc1
    Error stack in block where raised:
    ORA-06512: at "SCOTT.PROC1", line 4
    Error stack at top level:
    ORA-06512: at "SCOTT.PROC1", line 11
    ORA-06512: at "SCOTT.PROC2", line 6
    ORA-06512: at "SCOTT.PROC3", line 4
    
    Program owner = SCOTT
    Program name = PROC1
    Line number = 11
    

    When I call the function backtrace in the program at the lowest level, it correctly identifies the line 4 of proc1 as the line where the error is mentioned. I then re - raise the same exception using the statement of RECOVERY. When the exception propagates to the outermost block, I call the backtrace function once again and this time it shows that the error was raised at line 11 of proc1.

    This behavior, we can conclude that DBMS_UTILITY. FORMAT_ERROR_BACKTRACE watch the running back to the last trace LIFT during its session. As soon as you issue a STIMULUS to a specific exception or re - raise the current exception, you restart the cell which produces the backtrace function. This means that if you want to take advantage of the DBMS_UTILITY. FORMAT_ERROR_BACKTRACE, take one of the following two approaches:

    Call the function backtrace in the section of the exception to the block in which the error was raised. This way you have (and can connect) that line number critical, even if the exception is re-relief more further upward in the stack.
    Avoid exception handlers in your carpet intermediate programs and call the function backtrace in the section except for the outermost program in your stack.

    Full article available here

    http://www.Oracle.com/technology/oramag/Oracle/05-Mar/o25plsql.html

  • raise the exception ORA-00942

    -How to raise an exception for 6550 or 942?  Here is the anonymous block that I am running in SQL Developer, who does not throw an exception:

    --(J'ajouterais que c'est un exemple d'autonomes; le tableau "image_masterr" n'existe pas)

    -I am running in 10.2.0.1

    DECLARE
    lcl_temp1 VARCHAR2 (10);
    v_error_code NUMBER;
    v_error_message VARCHAR2 (255);
    no_table EXCEPTION;
    no_table_942 EXCEPTION;
    PRAGMA EXCEPTION_INIT(no_table,-06550);
    PRAGMA EXCEPTION_INIT(no_table_942,-00942);
    BEGIN
    DECLARE
    lcl_temp VARCHAR2 (20);
    BEGIN
    v_error_code: = SQLCODE;
    v_error_message: = SQLERRM;
    SELECT count (1) IN the lcl_temp of image_masterr;
    v_error_code: = SQLCODE;
    v_error_message: = SQLERRM;
    DBMS_OUTPUT. Put_line ("there is no problem ' |") lcl_temp);
    EXCEPTION
    WHEN no_table OR no_table_942 THEN
    DBMS_OUTPUT. Put_line ('there is a problem');
    WHILE OTHERS THEN
    DBMS_OUTPUT. Put_line ('there is a problem');
    END;
    DBMS_OUTPUT. Put_line ("it's no problem :'|| v_error_code | v_error_message);
    END;

    We must distinguish between exceptions at compile time and exceptions at run time. You can only handle exceptions at the moment is running. So if you have a static SQL referencing the nonexistent table you will get the compile error (btw, ora-06550 said explicitly you - compile error). Now if you have a dynamic sql code in your block PL/SQL with reference to non-existent table, you won't get compile time error. Exception will be thrown when you run the dynamic sql code. In this case, you can catch the error "table or view does not exist" and manipulate appropriatry.

    SY.

  • clear the table of loop for

    Hello world

    I have a question about the erasure of history to the table. It sounds simple, but I'm really confused...

    As the example attached below, I've built a table within a while loop and a loop. After totally run the program once, when I run it a second time, it seems that the table has a memory of the last time, that is the size of table does not start from 0, and appears the old number from last time, even through its initialization of the for loop.

    How can I make it go empty each time when I restart the table?

    Need your help. Thank you very much. : )

    You must also have a shift in the loop FOR. This will keep the data for the duration of the program, but it clear at the beginning of the next run.

  • Unable to raise the exception in the update procedure

    Hello

    Here, I am unable to lift the exception:

    create or replace procedure P_empNO1 (p_empno in emp.empno%type)

    as

    Start

    Update emp set = 'k' where empno = p_empno ename;

    exception

    When no_data_found

    then

    dbms_output.put_line (' ' no data ');

    end;

    Thank you

    Hello

    It is not an SQL error when you update and if 0 rows are updated.

    After the SQL is executed, you will have to get the count and if it's 0 then stripe your user defined exception.

    IF SQL%ROWCOUNT = 0 THEN
        RAISE no_update_err;
    END IF;

    Thank you

  • move the MCs with loop for?

    I am trying to find a way to move video clips with a for loop

    I have 10 points called t1d-dt10, and I want to be able to put them all to y = 200.

    I understand that I can put i = 1; i < 11; i ++

    as

    for (i = 1; i < 11; i ++) {}

    DT i._y plus 200 ;}

    or

    for (i = 1; i < 11; i ++) {}

    String("DT"+i)._y = 200 ;}

    but the rest is a mess, and does not, work or glitches. I still have to find a loop help file for the movement of several video clips.

    If you just want to immediately change the positions of the bodies, then using a for loop works fine, you just use the notation of support [] to have the strings to be interpreted as the name of the instances...

    for (i = 1; i<>

    This ["dt" + i] ._y = 200;

    }

  • For the verification of loop fetch

    Hi experts,

    As everyone knows, for loop taken 100 lines per each iteration (network roundtrips to 100 by default). Please, if it is correct me if I'm wrong, I know the following codes are the same.


    for rec in (select * from employess)

    loop

    do_some_work

    end loop;


    declare

    cursor c is select * from custtable where rownum < 10;

    type of my_t is table of c%rowtype;

    REC my_t;

    if not c%isopen then

    Open c;

    end if;

    loop

    Fetch c bulk collect into rec limit 100;

    do_some_work

    output when rec.count = 0;

    end loop;

    Close c;

    My question is, when I try to check the FOR LOOP to retrieve the query 100 lines per iteration, I use view v$ sql. However, it does not work. Because the PL/SQL block is ready. I need not to see that the sql that is used in the LOOP FOR query. So, what should I do to check that the extraction of LOOP FOR 100 rows per each iteration? Dynamic operating modes should I watch?

    Thanks in advance.

    You can simply enable SQL_TRACE and check. I used a TEMP table that has 1000 rows.

    SQL > select count (*) temp;

    COUNT (*)
    ----------
    1000

    SQL > alter session set sql_trace = true;

    Modified session.

    SQL > alter session set tracefile_identifier = "kar28042014";

    Modified session.

    SQL > start
    2 for i in (select * from temp)
    loop 3
    4 null;
    5 end of loop;
    6 end;
    7.

    PL/SQL procedure successfully completed.

    SQL > alter session set sql_trace = false;

    Modified session.

    If you see the trace output, you can see 11 extraction operation is done. 10 * 100 = 1000 read lines. The extra 1 extraction is to check if there is nothing else to look for.

    Parsing user id: 191    (recursive depth: 2)
    Rows    Row Source Operation-------  ---------------------------------------------------      1  SORT AGGREGATE (cr=14 pr=0 pw=0 time=883 us)  1000  TABLE ACCESS FULL TEMP (cr=14 pr=0 pw=0 time=185 us)
    ********************************************************************************
    
    call    count      cpu    elapsed      disk      query    current        rows------- ------  -------- ---------- ---------- ---------- ----------  ----------Parse        1      0.01      0.00          0          1          0          0Execute      2      0.00      0.00          0          0          0          0Fetch      11      0.00      0.00          0        23          0       1000------- ------  -------- ---------- ---------- ---------- ----------  ----------total      14      0.01      0.01          0        24          0       1000
    
  • Need help with the exception of slider

    Hello

    I have a small code with implicit cursor to retrieve rows in the unreadable_cards table, and then for each extracted value I search another table card_acnt to certain values and update data in the table unreadable maps. The code is as below

    declare

    number of v1;

    Start

    for v1 to (select engravedid in the unreadable_cards where case_resolved = 1)

    loop

    Update unreadable_cards set Serial_number = (select card_account Serial_number

    where ticketid = v1.engravedid)

    where engravedid = v1.engravedid;

    Update unreadable_cards set case_resolved = 2

    where case_resolved = 1

    Serial_number is not null;

    end loop;

    exception

    When no_data_found then

    Update unreadable_cards set case_resolved = 22

    where ticketid = v1.engravedid;

    When too_many_rows then

    Update unreadable_cards set case_resolved = 23

    where ticketid = v1.engravedid;

    When others then

    Update unreadable_cards set case_resolved = 24

    where ticketid = v1.engravedid;

    end;

    Here I have problem write values to the table as this error pops up for each reference to V1 in exception

    PLS-00487: Invalid reference to the variable "V1".

    I have to be able to raise all three exceptions in the loop so that v1 can be referenced and loop will not terminate on the meeting of the exception and complete for each row retrieved by cursor, so that I can track the status of each record based on the value of case_resolved.


    Any help would be much appreciated

    Thank you

    Saurabh

    Let me to you that out of me... I don't like your code

    First thing you need to know, it's you won't hit NO_DATA_FOUND exception in an UPDATE statement. If an update has not changed a line, it does not raise an exception NO_DATA_FOUND. Check this

    SQL > start
    Update 2 emp set sal = sal + 10, where 1 = 2;
    3 end;
    4.

    PL/SQL procedure successfully completed.

    No exception. It's a thing, you have to watch.

    Second thing I don't like the way you used the WHEN OTHERS exception. What are the exception as you look? You should not have a when others without STIMULUS. IT a bug in the code. You must fix this.

    Assuming that your assignment CASE_RESOLVED logic, that's how.

    CASE_RESOLVED = 2 means you have found an exact match for your UNREADABLE_CARDS. ENGRAVEDID in CARD_ACCOUNT. TICKETID

    CASE_RESOLVED = 22 means that you do not have a match for your UNREADABLE_CARDS. ENGRAVEDID in CARD_ACCOUNT. TICKETID

    CASE_RESOLVED = 23 means that you have several game for your UNREADABLE_CARDS. ENGRAVEDID in CARD_ACCOUNT. TICKETID

    CASE_RESOLVED = 24, does not have any meaning. You have to drop that part.

    You can do this, you have no need for all that PL/SQL. A simple SQL way will do.

    Fusion in unreadable_cards x

    a_l'_aide_de)

    Select a.engravedid

    max (b.serial_number) Serial_number

    case when count (b.serial_number) = 1 then 2

    When count (b.serial_number) = 0 then 22

    When count (b.serial_number) > 1 then 23

    end case_resolved

    of unreadable_cards one

    left

    Join card_account b

    On a.engravedid = b.eticketid

    where a.case_resolved = 1

    Group

    by a.engravedid

    ) y

    on)

    x.engravedid = y.engravedid

    )

    When matched then

    update the value x.serial_number = nvl (y.serial_number, x.serial_number)

    x.case_resolved = y.case_resolved;

    Above is untested code. But should work. If any minor error fix it and you should be good to go.

  • New loops for 10.1.1 even as new loops of logic?

    I have all the additional content for Logic Pro and with the exception of the fabric of Alchemy, are the new Apple Loops for Garageband 10.1.1 identical to what I already under Logic Pro?

    GarageBand gives me the option to download the entire library, which I don't want I don't have to.

    I suspect these new loops for GarageBand 10.1.1 are already in my folders of loops when I updated Logic Pro a few months ago?

    Thank you

    Robert

    T

    The App Store shows the update like this:

    2600 new Apple Loops and sounds.

    I also installed Logic Pro X.

    There is no new loops installed after 10.11.1 GarageBand update.   The last loop in Library/Audio/Apple Loops is 80 return Beat.caf frommay 2015

    GarageBand must have installed something, because the absence of plug-ins error messages are gone, when I open iOS projects GarageBand, but I can't find any new items in the folder/library.

    I'm now trying to download all the available sounds. We'll see what happens.

  • Catch the Exception and continue

    Hello

    If the exception was framed but would like to continue anyway to another step (for example, Insert statement or create index)

    < pre >
    sql_stmt1: = 'DROP INDEX PRD_GLO_SDX;
    EXECUTE IMMEDIATE sql_stmt1;
    EXCEPTION
    WHILE OTHERS THEN
    raise_application_error (-20001, SQLERRM |) » '||' CANNOT DELETE THE INDEX OF PROBABILITY THAT THE INDEX MAY NOT EXIST");
    < / pre >

    Can anyone give advice on continue even if there is an exception?

    See you soon.

    do not raise the exception, if you do not want.

    sql_stmt1  :='DROP INDEX PRD_GLO_SDX';
      EXECUTE IMMEDIATE sql_stmt1;
       EXCEPTION
                WHEN OTHERS THEN
    --               raise_application_error(-20001,SQLERRM||' '||'PROBABLITY INDEX CANT BE DROPPED AS INDEX MAY NOT EXIST');
    null;
    

    It is best to use a specific error to handle instead of the "catch-all", SO that OTHERS

  • Management concept the exceptions that went wrong!

    Well, this is by far the most embarrassing hack code I've done so far... but it works. I'm trying to run a select where if there is no data or null returned, place it in the value "v_pidm"and then let the action happen.» Pretty simple, right? Fake! A select statement returns no data that uses a function 'en' is an exception... "no data found". Oracle, it sends to the exception block as it should. Well, I don't want to stop and start my script a million times here, I added a Begin/End sub, with an exception to handle the error to say and perform an insert. I know that you should not use a State of exception for inserts another capture errors... you know bad practices and all. Any ideas as how to better manage the select statement that must regularly return no data? I was thinking some along the line of nvl (v_pidm, 0) or something, but I get errors.
    set serveroutput ON SIZE 1000000
    set heading off                
    set feedback off                
    set trimspool off               
    set echo off                    
    set pagesize 0  
    set termout on
    
    
    Declare
    error     varchar(255); 
    v_pidm    number(8); 
    
     Begin
        Begin    
            select distinct saraatt_pidm  
    
            into
    
            v_pidm
    
            from saraatt, saradap
            where saraatt_appl_no = SARADAP_APPL_NO
            and saraatt_term_code = SARADAP_TERM_CODE_ENTRY
            and saraatt_pidm = 4;
            
          Exception
             when too_many_rows then
            error := SQLERRM;        
            DBMS_OUTPUT.PUT_LINE(' %% Oracle Error! %% The select statement returned more than two rows ');
               
            when no_data_found then
            error := SQLERRM;        
            DBMS_OUTPUT.PUT_LINE('Select Returned No Data . . . Therefore Insert new record for ' || v_pidm );
            
            v_pidm := -999;
    
            when others then
            error := SQLERRM;        
            DBMS_OUTPUT.PUT_LINE(' %% Oracle Error! %% An Error Occured ' || substr(error,5,20));    
        End;
        
        
        
     DBMS_OUTPUT.PUT_LINE('Pidm: ' || v_pidm);
    
     End;

    There is nothing inherently wrong with code like

    BEGIN
      SELECT column_name
        INTO l_variable_name
        FROM table_name
       WHERE some_where_clause;
    EXCEPTION
      WHEN no_data_found
      THEN
        l_variable_name := 0;
    END;
    

    It is perfectly reasonable to have exception handlers that make anything other than newspaper an exception if they can in fact wisely handle the exception (e.g., you know that the query may return 0 rows and you know how to handle this case correctly).

    You don't want an exception handler that simply calls to DBMS_OUTPUT. Put_line without re-raise the exception. It is a mistake to delay. And there is no real reason in this case to extract the SQLERRM in the variable error - it would be better to let the exception is propagated to the top so that you can see the full error stack.

    Justin

  • How will I know if new loops for 10.1.1 has uploaded?

    So I downloaded the new update, but I can't say the old the new loops loops.  Download it and install it or I have to click on the option 'Download the sounds available' in the menu?

    OR

    Can someone give me the name of loop for one of the loops again so I can search my library of loop?  Thank you!

    It is no new loops have been installed for me, but they may have been installed earlier by the logic. Maybe the update adds iOS GarageBand loops, take a look at this list.

    How to get iOS GB loops in GarageBand for Mac.

  • Raises an exception if the cursor failed

    Hi, how can I write an exception if a cursor was unable to retrieve the values in the variable? for example, I have 10 cursors in procedures from my store and I want if this cursor was not able to process then threw an exception. For example, code below, if the recovery process could not then triggered an error message like "failure on cursor c_get_card_dependencies.

    OPEN c_get_card_dependencies (v_POTENTIAL_CARDS.iv_sysid, v_POTENTIAL_CARDS.plp_log_pos_type);

    LOOP

    SEEK c_get_card_dependencies INTO v_CARD_DEPENDENCIES;

    EXIT WHEN c_get_card_dependencies % notfound;

    DBMS_OUTPUT. Put_line (LPAD ('SYS ID: ', LENGTH ('SYS ID: "") + 2' ') |) v_CARD_DEPENDENCIES.sysid);

    END LOOP;

    CLOSE C_get_card_dependencies;

    Put your OPEN... CLOSE in a BEGIN... END of block. Then, you can catch the exceptions for each cursor and raising your own exception

    BEGIN

    XY OPEN;

    ...

    NARROW xy;

    EXCEPTION

    WHEN VALUE_ERROR THEN

    raise_application_error (-20001, "failed on the xy cursor: ' |") SQLERRM, TRUE);

    END;

  • Continue the loop after the exception thrown in SQL

    How would continue the while loop in the code below after an exception was thrown?

    DECLARE    
    v_blob_data       BLOB;    
    v_blob_len        NUMBER;    
    v_position        NUMBER;    
    v_raw_chunk       RAW(10000);    
    v_char      CHAR(1);    
    c_chunk_len   number       := 1;    
    v_line        VARCHAR2 (32767)        := NULL;    
    v_data_array      wwv_flow_global.vc_arr2;    
    v_rows number;    
    v_sr_no number := 1;  
    v_first_line_done boolean := false;  
    v_error_cd number :=0;  
    v_quote_pos1 NUMBER;  
    v_quote_pos2 NUMBER;  
    v_enclosed_str VARCHAR(200);
    v_errmsg VARCHAR2(4000);
    
    BEGIN
    
     delete from TEMP_MM_UPDATE where username = :P1_USER_ID;
    
    -- Read data from wwv_flow_files</span>    
     select    
      blob_content    
     into v_blob_data    
     from wwv_flow_files    
     where name = :P2_FILE_UPLOAD; 
    
     v_blob_len := dbms_lob.getlength(v_blob_data);    
     v_position := 1;
    
    
    
     -- Read and convert binary to char</span>  
     WHILE ( v_position <= v_blob_len )    
     LOOP
    
    begin 
     
      v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);    
      v_char :=  chr(hex_to_decimal(rawtohex(v_raw_chunk)));    
      v_line := v_line || v_char;    
      v_position := v_position + c_chunk_len;
      
     -- When a whole line is retrieved </span>   
     IF v_char = CHR(10) THEN
     
     LOOP  
      --Make sure there's something to replace  
      IF INSTR(v_line, '"', 1, 1) = 0 THEN  
      EXIT; -- If nothing to replace, exit loop and don't try  
      END IF;  
      --Find the position of the first and second quotes in the line of text  
      v_quote_pos1 := INSTR(v_line, '"', 1, 1);  
      v_quote_pos2 := INSTR(v_line, '"', 1, 2);  
      --Extract the inner string  
      v_enclosed_str := SUBSTR(v_line, v_quote_pos1 + 1, v_quote_pos2 - v_quote_pos1 - 1);  
      --perform the replacement  
      v_line := SUBSTR(v_line, 0, v_quote_pos1 - 1) || REPLACE(v_enclosed_str, ',', '<') || SUBSTR(v_line, v_quote_pos2 + 1);  
     END LOOP; 
      
     -- Convert comma to : to use wwv_flow_utilities </span>  
     v_line := REPLACE (v_line, ',', ':');  
     v_line := REPLACE (v_line, '<', ',');  
     v_line := REPLACE (trim(v_line), '-', NULL);  
     --v_line := REPLACE (trim(v_line), '"', NULL);  
     -- Convert each column separated by : into array of data </span>    
     v_data_array := wwv_flow_utilities.string_to_table (v_line);  
     --Check to see if the row of column headers has already been parsed through  
     IF(v_first_line_done != true)THEN   
      v_first_line_done := true;  
      --Check column order in spreadsheet  
      IF(v_data_array(1)   LIKE '%Username%' AND
        v_data_array(2)  LIKE '%NDN%' AND
        v_data_array(3)  LIKE '%PCFN%' ) THEN   
       v_error_cd := 0;  
       v_line := NULL;  
      ELSE  
       v_error_cd := 1;  
      END IF;  
     --If first line is done and the column order is correct then  
     ELSIF(v_first_line_done = true AND v_error_cd = 0) THEN   
     -- Insert data into target table </span>    
     EXECUTE IMMEDIATE 'insert into TEMP_MM_UPDATE   
     (USERNAME,
       RPT_FLAG,
      PCFN)
     values (:1,:2,:3)'   
       USING   
      v_data_array(1),   
      v_data_array(2),   
      v_data_array(3);
       -- Clear out    
      v_line := NULL; v_sr_no := v_sr_no + 1; 
     
     END IF;  
     END IF;
    
    exception
    WHEN OTHERS then
      v_errmsg := SQLERRM;
      insert into temp_mm_update (username,error_desc)
      values (:P1_USER_ID, v_errmsg);
    end;
      
     END LOOP;
    
    
     
    DELETE FROM WWV_FLOW_FILES where name = :P2_FILE_UPLOAD;
    DELETE FROM TEMP_MM_UPDATE WHERE USERNAME IS NULL AND PCFN IS NULL;  
     IF(v_error_cd = 1) THEN  
    INSERT INTO temp_mm_update (USERNAME, ERROR_DESC)  
    VALUES (:P1_USER_ID, 'Error. Please check column order in spreadsheet.');  
    END IF;
    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            insert into temp_mm_update (username,error_desc)
      values (:P1_USER_ID, 'No Data Found.');
     WHEN OTHERS then
      v_errmsg := SQLERRM;
      insert into temp_mm_update (username,error_desc)
      values (:P1_USER_ID, v_errmsg);  
    
    END;
    
    

    When I set the exception inside the loop, as above, the procedure seems never to end, and I end up getting a 'NOWAIT' error when I try to remove the table or something like that.

    The code works fine if I remove the 'START' just after the loop and also out of the exception within the loop, but I want to be able to specify what's wrong with each record rather than deal with the correct records and then stop after that it is a record that has, for example, 9 values in a column that accepts only 6.

    Can anyone help with this?

    Thank you

    Steven

    Play with my code I found what was wrong.
    I needed to add in the following line in my code block of exception:
    v_line := NULL; v_sr_no := v_sr_no + 1;
    
    Final code:
    DECLARE
      v_blob_data       BLOB;
      v_blob_len        NUMBER;
      v_position        NUMBER;
      v_raw_chunk       RAW(10000);
      v_char      CHAR(1);
      c_chunk_len   number       := 1;
      v_line        VARCHAR2 (32767)        := NULL;
      v_data_array      wwv_flow_global.vc_arr2;
      v_rows number;
      v_sr_no number := 1;
      v_first_line_done boolean := false;
      v_error_cd number :=0;
      v_quote_pos1 NUMBER;
      v_quote_pos2 NUMBER;
      v_enclosed_str VARCHAR(200);
      v_errmsg VARCHAR2(4000);
    BEGIN
      delete from TEMP_MM_UPDATE where username = :P1_USER_ID;
    
      -- Read data from wwv_flow_files
      select
        blob_content
        into v_blob_data
        from wwv_flow_files
        where name = :P2_FILE_UPLOAD; 
    
      v_blob_len := dbms_lob.getlength(v_blob_data);
      v_position := 1; 
    
      -- Read and convert binary to char
      WHILE ( v_position <= v_blob_len )
      LOOP
        begin
            v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);
            v_char :=  chr(hex_to_decimal(rawtohex(v_raw_chunk)));
            v_line := v_line || v_char;
            v_position := v_position + c_chunk_len;
    
          -- When a whole line is retrieved 
          IF v_char = CHR(10) THEN
            LOOP
              --Make sure there's something to replace
              IF INSTR(v_line, '"', 1, 1) = 0 THEN
                EXIT; -- If nothing to replace, exit loop and don't try
              END IF;
              --Find the position of the first and second quotes in the line of text
              v_quote_pos1 := INSTR(v_line, '"', 1, 1);
              v_quote_pos2 := INSTR(v_line, '"', 1, 2);
              --Extract the inner string
              v_enclosed_str := SUBSTR(v_line, v_quote_pos1 + 1, v_quote_pos2 - v_quote_pos1 - 1);
              --perform the replacement
              v_line := SUBSTR(v_line, 0, v_quote_pos1 - 1) || REPLACE(v_enclosed_str, ',', '<') || SUBSTR(v_line, v_quote_pos2 + 1);
            END LOOP; 
    
            -- Convert comma to : to use wwv_flow_utilities 
            v_line := REPLACE (v_line, ',', ':');
            v_line := REPLACE (v_line, '<', ',');
            v_line := REPLACE (trim(v_line), '-', NULL);
            --v_line := REPLACE (trim(v_line), '"', NULL);
            -- Convert each column separated by : into array of data 
            v_data_array := wwv_flow_utilities.string_to_table (v_line);
            --Check to see if the row of column headers has already been parsed through
            IF(v_first_line_done != true)THEN
              v_first_line_done := true;
              --Check column order in spreadsheet
              IF(v_data_array(1)    LIKE '%Username%' AND
                  v_data_array(2)  LIKE '%NDN%' AND
                  v_data_array(3)  LIKE '%PCFN%') THEN
                v_error_cd := 0;
                v_line := NULL;
              ELSE
                v_error_cd := 1;
              END IF;
            --If first line is done and the column order is correct then
            ELSIF(v_first_line_done = true AND v_error_cd = 0) THEN
              -- Insert data into target table 
              EXECUTE IMMEDIATE 'insert into TEMP_MM_UPDATE
              (USERNAME,
               RPT_FLAG,
               PCFN)
              values (:1,:2,:3)'
               USING
                v_data_array(1),
                v_data_array(2),
                v_data_array(3);
               -- Clear out
                v_line := NULL; v_sr_no := v_sr_no + 1;
            END IF;
          END IF;
        exception
          WHEN OTHERS then
            v_errmsg := SQLERRM;
            insert into temp_mm_update (username,error_desc)
            values (:P1_USER_ID, v_errmsg);
    v_line := NULL; v_sr_no := v_sr_no + 1;
      END;
      END LOOP;
    
      DELETE FROM WWV_FLOW_FILES where name = :P2_FILE_UPLOAD;
      DELETE FROM TEMP_MM_UPDATE WHERE USERNAME IS NULL AND PCFN IS NULL;
      IF(v_error_cd = 1) THEN
        INSERT INTO temp_mm_update (USERNAME, ERROR_DESC)
        VALUES (:P1_USER_ID, 'Error. Please check column order in spreadsheet.');
      END IF;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        insert into temp_mm_update (username,error_desc)
        values (:P1_USER_ID, 'No Data Found.');
      WHEN OTHERS then
        v_errmsg := SQLERRM;
        insert into temp_mm_update (username,error_desc)
        values (:P1_USER_ID, v_errmsg);
    END;
    
  • Issue with the exception of the loop

    Hello

    I had 4 database, I use dblinks to check some tables and write the results in a table. I have created a table to contain the instance names so that my loop check and perform my procedure.

    declare

    sql_string1 VARCHAR2 (4000);

    sql_string2 VARCHAR2 (100);

    Start

    sql_string2: = "truncate table Backup."

    immediately run sql_string2;

    for r in (select INSTANCE_NAME, del HOST_NAME)

    loop

    sql_string1: = ' insert into Backup

    SELECT "' | r.HOST_NAME | " '  '||', '''|| r.INSTANCE_NAME | " '  '||' ,

    INPUT_TYPE, STATUS, START_TIME, END_TIME V$RMAN_BACKUP_JOB_DETAILS@'|| r.INSTANCE_NAME;

    immediately run sql_string1;

    COMMIT;

    end loop;

    exception

    WHILE OTHERS THEN

    NULL;

    end;

    /

    If all listeners work or dbs work this procedure to work with no problems but if one of them is closed, simply insert the values until it gets error but I want that if she gets error will be another value. How can I do?

    I changed the values in the table led

    SYS@crofxd01:WSTORED: > select instance_name del;

    INSTANCE_NAM

    ------------

    BLABLA

    BLABLA

    BLABLA

    BLABLA

    FPT

    only the FPT is actual instance after I performed the procedure, I want to see that FPT values inserted DB.

    Thank you

    You must move the exceptions in the loop. Like this

    declare
    sql_string1 VARCHAR2 (4000);
    sql_string2 VARCHAR2 (100);
    Start
    sql_string2: = "truncate table Backup."
    immediately run sql_string2;
    for r in (select INSTANCE_NAME, del HOST_NAME)
    loop
    sql_string1: = ' insert into Backup
    SELECT "' | r.HOST_NAME | " '  '||', '''|| r.INSTANCE_NAME | " '  '||' ,
    INPUT_TYPE, STATUS, START_TIME, END_TIME
    OF V$RMAN_BACKUP_JOB_DETAILS@'|| r.INSTANCE_NAME;
    Start
    immediately run sql_string1;
    exception
    When then
    null;
    end;

    COMMIT;
    end loop;
    end;

    But make sure that you specify that the exception in the EXCEPTION block. Do not THEN use than OTHERS. Because it will catch all exceptions (long-awaited by you and should not not by you). It will hurt one day.

Maybe you are looking for