Throwing exceptions in PL/SQL

Hi friends

I have the following code:

declare

var1...
var2...
cursor c1

Start

Insert stmt;

Update stmt;

Update stmt;

to r1 c1 loop
end loop;

end;

Each month I will be having about 6 million lines in the process. In order to throw exceptions, I think of one of the following options:

Option 1_
declare

var1...
var2...
var3 exception;
var4 exception;
VAR5 exception;

cursor c1

Start

Insert stmt;

Update stmt;
IF SQL % NOTFOUND then
var3;
end if;


Update stmt;

IF SQL % NOTFOUND then
var4;
end if;


to r1 c1 loop
end loop;

IF SQL % NOTFOUND then
VAR5;
end if;

Exception
When var3 then blah blah
When var4 then blah blah
When var5 then blah blah

end;

Option 2_

declare

var1...
var2...

cursor c1

Start

Insert stmt;

Update stmt;

Update stmt;


to r1 c1 loop
end loop;

Exception
While some other then blah blah
end;

In terms of performance, which is better? And is there a better option?

Thank you...

Ways to handle exceptions known or predictable management of exceptions.

The use of OTHERS WHEN in most cases implies that you don't know what exceptions will occur and so it's a bad habit.

It is always better to define known exceptions and capture those explicitly and manage them properly. Then, if any exception occurs, she really is and the exception and should cause the program to fail and certainly should not be ignored, because it was not intended.

Tags: Database

Similar Questions

  • Throwing exceptions of h

    HIE

    I have a public method in my AM I want to expose as a client method to call from a managed bean.

    I have a method like signature

    public Long myMethod (String val);

    If I go to AM and click the Edit then I see this method on the left side of the shuttle to expose it.

    But as soon as I add bird Exception this method is no longer available.

    So why does this happen?

    Hello

    You throw exceptions?
    You may need to use local instead of Exception.

  • EXECUTE IMMEDIATE throws exception NO_DATA_FOUND when it should not

    Hi all

    I wrote an anonymous PL/SQL block that, on paper, should be OK, but one of its commands EXECUTE IMMEDIATE is runnning slowing prematurely and throw an exception NO_DATA_FOUND, when it should not because I know that there is data in the table.

    Here is the line that I suspect is out of steam after 8 attempts:


    ---
    immediately execute "INSERT INTO ple101.circular35 (ID, SLAVETABLEID, SLAVEITEMID, MASTERTABLEID, MASTERITEMID, PRO) (SELECT * FROM SLAVETASKS where mastertableid =' |)" subTableID | "and masteritemid =' |" subitemID |' and subtableid =' | mastTableID | "and SLAVEITEMID =' |" mastItemId |') ' ;
    ------

    It is supposed to search the entire SLAVETASKS table for documents that match the WHERE clause, but gives up after 8 cycles.
    Table SLAVETASKS got 10228 records.

    The above statement (and the whole of the PLSQL block) is good in that it gets records if they are wthin the first 8 records in the SLAVETASKS table, but like I said after 8 records, to throw an exception NO_DATA_FOUND.

    Published by: user10390960 on April 28, 2012 03:21

    Published by: user10390960 on April 28, 2012 03:22

    Published by: user10390960 on April 28, 2012 03:23

    Published by: user10390960 on April 28, 2012 05:08

    Hi Goofy,

    The above script is for PLSQL and if you want to display the data in circular 35 follow like that

    # Save the code below in the sqlscript for example. circular_process_display. SQL and run as

    sqlplus /@ @circular_process_display.sql

    -- CREATE TABLE circular 35
    CREATE TABLE circular35
    ....
    ..
    /
    
    -- Execute PLSQL Block as given in my earlier post
    DECLARE
    ...
    BEGIN
    ...
    EXCEPTION
    ...
    END;
    /
    
    -- Run SQL to display output on screen.
    SET SERVEROUTPUT ON SIZE 100000 FEEDBACK ON LINESIZE 200;
    
    SELECT *
    FROM circular35
    /
    
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
    
  • setARRAYatName throws exception-> discussion of named parameter by default/now

    Hi, I'm pretty new with the help of JDBC and
    I have a question about using the following method of an OracleCallableStatement setARRAYatName, so I don't have to fill in default values (I guess this is corect?)
    the signing of sqlmethod I call

    PROCEDURE create_timecard_bb)
    p_start_time IN hxc_time_building_blocks.start_time%TYPE,
    p_stop_time IN hxc_time_building_blocks.stop_time%TYPE,
    -p_approval_status IN hxc_time_building_blocks.approval_status%TYPE,
    p_resource_id IN hxc_time_building_blocks.resource_id%TYPE,
    -default to anyone because there is no other type of resource at the present time.
    p_resource_type IN hxc_time_building_blocks.resource_type%TYPE
    DEFAULT hxc_timecard.c_person_resource
    -We can't use approval_style_name because it is not unique.
    p_approval_style_id IN hxc_time_building_blocks.approval_style_id%TYPE
    DEFAULT NULL,
    p_comment_text IN hxc_time_building_blocks.comment_text%TYPE
    DEFAULT NULL,
    p_app_blocks hxc_block_table_type IN OUT NOCOPY,
    p_time_building_block_id OUT NOCOPY hxc_time_building_blocks.time_building_block_id%TYPE
    );

    The following code works.

    String stmtString = "start HXC_TIMESTORE_DEPOSIT.create_timecard_bb(?,?,?,?,?,?,?,?); end; « ;
    cstmt = conn.prepareCall (stmtString) (OracleCallableStatement);
    System.out.println (cstmt.getParameterMetaData (). GetParameterCount());
    / * FOLLOWIG CODE WORKS BUT IT IS WITH INDEX
    */
    GregorianCalendar calendar = new GregorianCalendar();
    Calendar.Set (2009, Calendar.JUNE, 1);
    cstmt.setDate (1, java.sql.Date (calendar.getTime () .getTime ())) of new;
    Calendar.Set (2009, Calendar.JUNE, 7);
    cstmt.setDate (2, new java.sql.Date (calendar.getTime () .getTime ()));
    cstmt.setInt (3, 4760);
    cstmt.setString(4,"PERSON"); default value
    cstmt.setInt (5,267); set, a value can also be null by default
    cstmt.setNull VARCHAR (6); default value is normally zero
    cstmt.setARRAY (table 7);
    cstmt.registerOutParameter(8,INTEGER);
    cstmt.registerOutParameter (TABLE 7, "HXC_BLOCK_TABLE_TYPE");

    ... during the extraction of results

    the following does NOT work code and throws an exception that er is een parameternaam geprobeerd in you stellen die niet voorkomt in SQL code of. : p_app_blocks (translated: you have tried to assign a parametername which does not excist in sql code)

    String stmtString = "start HXC_TIMESTORE_DEPOSIT.create_timecard_bb(?,?,?,?,?,?,?,?); end; « ;
    cstmt = conn.prepareCall (stmtString) (OracleCallableStatement);
    System.out.println (cstmt.getParameterMetaData (). GetParameterCount());
    / * the following code does not work, for arrayatname, difference which is parametesr with the default are not assigned by name, otherwise they are now affected by his name,

    GregorianCalendar calendar = new GregorianCalendar();
    Calendar.Set (2009, Calendar.JUNE, 1);
    cstmt.setDate ("p_start_time", new java.sql.Date (calendar.getTime () .getTime ()));
    Calendar.Set (2009, Calendar.JUNE, 7);
    cstmt.setDate ("p_stop_time", new java.sql.Date (calendar.getTime () .getTime ()));
    cstmt.setInt ("p_resource_id", 4760);
    cstmt.setARRAYAtName ("p_app_blocks", array); <-DURATION says this line throws an exception
    cstmt.registerOutParameter ("p_time_building_block_id", INTEGER);
    cstmt.registerOutParameter ("p_app_blocks", ARRAY "HXC_BLOCK_TABLE_TYPE");

    */

    So I make a false assumption that if you assign one with the name of those you do not assign a default value?
    Or something is wrong with setARRAYAtName?

    PS the trace (in Dutch)

    Exception in thread "main" java.sql.SQLException: Er is een parameternaam geprobeerd in you stellen die niet voorkomt in SQL code of. :
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
    at oracle.jdbc.driver.OraclePreparedStatement.setARRAYAtName(OraclePreparedStatement.java:6065)
    at be.interaccess.timecard.TimecardDaoImpl._doCreateTimecard(TimecardDaoImpl.java:268)
    at be.interaccess.timecard.TimecardDaoImpl.main(TimecardDaoImpl.java:210)

    Published by: user2561357 on May 27, 2009 13:48

    Looks like it says here

    http://download.Oracle.com/docs/CD/B28359_01/Java.111/b31224/oraint.htm#CHDBGJFG

    (b) bind parameters by name

    What is the reason behind this requirement? Any reason why you cannot use solution 1?

  • DeviceInfo.getDeviceName throws exceptions?

    Hello

    In my application I want to know what mobile, the application runs. Then I use the DeviceInfo functions.

    But DeviceInfo.getDeviceName () sometimes throws an exception!

    DeviceInfo.getDeviceId () a front line still works well.

    So far I can't tell when DeviceName works and when not... But it's the same application on the same mobile.

    Any idea?

    Here is the log:

    Unauthorized attempt to attach to this applicationnet_rim_cldc-9(4E68CC9F)
     Application
     getApplication
     0x336F
    net_rim_cldc-8(4E68CC9F)
     EventListenerManager
     add
     0x255C
    net_rim_cldc-9(4E68CC9F)
     MemoryCleanerManager
     addListener
     0x78C1
    net_rim_cldc-9(4E68CC9F)
     MemoryCleanerDaemon
     addWeakListener
     0x7625
    net_rim_cldc-6(4E68CC9F)
     ResourceBundleFamily$MyIntHashtable
     
     0xB223
    net_rim_cldc-6(4E68CC9F)
     ResourceBundleFamily
     
     0xB1B5
    net_rim_cldc-6(4E68CC9F)
     ResourceBundle
     getBundle
     0xAC43
    net_rim_cldc-6(4E68CC9F)
     ResourceBundle
     getBundle
     0xABD4
    net_rim_cldc-11(4E68CC9F)
     DeviceInfo
     getDeviceName
     0x16B1
    

    interpreting the stacktrace that looks like a bug to me, report it in jira.

  • InputStream in device throws exception SaxParser

    Hi all, I am working on OS 5.0.

    In my application, I have connected to the network using HttpConnection. I've added the necessary parameters to test the device. The connection sets up in the device, but it is throwing

    '& #x1f' SaxParser invalid character exception

    I don't know that that's the problem with InputStream, but not with the Httpconnection.

    a strange beviour, I've observed while debugging in the Simulator is... When I pass a URL with parameters make me same thing '& #x1f' bad character SaxParser exception, but if I pass the direct URL without setting the XML file is the analysis and works very well.

    any1 has faced previously this kind of problem? How to solve this problem?

    If the data from the server is compressed, then you will need to decompress before feeding it to the parser. If the data are encoded with gzip (uncompressed), try something like this:

    HttpConnectionFactory connFactory = new HttpConnectionFactory(_XMLUrl);connection = (HttpConnection)connFactory.getNextConnection();if (connection.getResponseCode() == HttpConnection.HTTP_OK) {    inputstream = new GZIPInputStream(connection.openInputStream());    parser.parse(new InputSource(inputstream));} else {    // error}
    

    If the server really uses zip compression, then you will need to use a ZlibInputStream. It is less likely, because the zip compression is oriented file, while gzip is aligned flow and more commonly used for responses from the server.

    A few other notes about your code:

    1. you don't need to create an InputStreamReader; the Analyzer can understand the encoding of the data of the (inflated) input stream itself.
    2. You must use connection.openInputStream () instead of connection.openDataInputStream (). Expect UTF-8 text, not Java data types, in the input stream.
    3. Definition of the Content-Type request property is not make sense unless you publish data to _XMLUrl (which, from your code, you do not).
    4. If the server powers up properly the response headers, you can check if the answer is gzip-ed using "gzip".equals (connection.getEncoding ()) after the call to connection.openInputStream (). " (My suggested code blindly guess gzip). Don't forget to check, however, that the process server is actually defining the header of the correct answer. many authors of server scripts don't know or are lazy about it. (If you control both sides, of course, you can safely be lazy.)
    5. In your second example in code, you should probably be defining the request text/xml HEADER_ACCEPT, instead of HEADER_ACCEPT_ENCODING property. Typical values for Accept-Encoding are 'gzip', 'compress' and 'identity', not ' text/xml '.
  • GuestScript feeder throws exception socket

    Hi all

    GuestScript feeder throws the following exception.

    [08:01:53.722 2016-06-30] [W] unknown error. The error happened the following output handler:; nested exception is:

    java.net.SocketTimeoutException: read timed out (Workflow: Get deals with the task (item1) invited / Scriptable #8)

    It is impossible to read the client process. Any suggestions?

    Thank you

    Well... There was 1 cpu which has been 100%...added another CPU, which solved the problem

  • Plugins and Java methods that throw exceptions

    I am trying to determine how to deal with my plugin with expose an object method java which could raise and exception.  For the example below, I've added a mapping object for the exception class and the getErrno and getReason methods

    I have in my java script

    try {}

    Method.Invoke ();

    }

    {} catch (e)

    errno = e.getErrno ();

    }

    the e I catch is going to be my java exception object, or is it something else?

    When I run it (whose value invoke throws the exception) I get "TypeError: function getErrno is not found.

    Basically, all exceptions are string message, not the exception objects. What you can do is to serialize the error and the message that the Exception string is the excpeptions object.

  • XmlType extractValue with namespace throw exception "invalid token".

    Hello. I have XML stored as XMLTYPE and with content, such as:

    + < notificationEF > +.
    + < oos:id > 2812301 < / oos:id > +.

    When I try to run

    extractValue (XML_CLOB, ' notificationEF / oos:id ')

    I catch exception "LPX-00601: token not valid in:" notificationEF / oos:id' "."

    What's wrong? And how do I fix it?

    Thank you.

    Here's one way:

    SQL> var xmldoc varchar2(4000)
    SQL>
    SQL> begin
      2   :xmldoc :=
      3  '
      4  
      7   
      8    4711561
      9    4711561
     10   
     11  ';
     12  end;
     13  /
    
    PL/SQL procedure successfully completed
    
    SQL> SELECT x.id
      2  FROM XMLTable(
      3         XMLNamespaces(
      4           default 'http://example.ru/oos/export/1'
      5         , 'http://example.ru/oos/types/1' as "oos"
      6         )
      7       , '/export/contract/oos:id'
      8         passing xmltype(:xmldoc)
      9         columns id number path '.'
     10       ) x
     11  ;
    
            ID
    ----------
       4711561
       4711561
     
    
  • Throwing exception of validation is not shown in the jspx page

    Hello

    I have a page with af:table that uses a display object. This view object uses an entity object. In the method of the EntityImpl of my entity object class I throw ValidationException.I debug the application and I saw that it is throwing the exception. But it is not displayed on the page. What could be wrong here?

    try {}
    setAttributeInternal (BANKTYPE, value);
    }
    {} catch (TooManyObjectsException e)
    e.printStackTrace ();
    throw new ValidationException ("you try to add the existing record");

    }
    Is to have my page jspx * < af:messages id = "m1" / > *.
    Jspx page should any configuration to show the exception thrown in a popup?

    Kind regards
    Priya.

    You can try the same thing with the local...

  • Help with «throw exception error native function»

    Can someone help me find a soultion error with dreamweaver mx2004. I use the software successfully for several years and everything has started to develop a new site with .htm files.

    When connecting to a css file, I get the following error when I swith from design mode, the system displays the error code, then crashes, but only on a single page, another page using the same css file works fine! I'm totally baffled...

    The error is:

    When executing command DW_DesignView in toolbars.xml, the following JavaScript error occurred: exception throw in native function


    I hope that its not me, but it just may be, please help.

    If this is the case with a single file, there is something wrong with this file. Or to be more precise, there is something in this file that gives indigestion to Dreamweaver. You must check the file with the validator W3C CSS (http://jigsaw.w3.org/css-validator/).

    There is a known issue with Dreamweaver CS3, for which a file that is exactly 8 KB or multiples of it causes Dreamweaver to crash. I've never heard of him with Dreamweaver MX 2004, but if the file is valid, try to open it in a text editor and add something, as a CSS comment. This increases the size of the file and get rid of the problem.

    If these ideas do not resolve the problem, I'm afraid, I'm out of ideas. Adobe will not help you because your version of Dreamweaver is no longer supported.

  • exception in PL/SQL block error

    Hello
    the following conditions in a PL/SQL block cause an exception error to occur?

    A Select statement - does not return a line.
    B - Select statement returns multiple lines.

    Thank you.

    If you talk to SELECT... IN... statement:

    A Select statement - does not return a line.

    Yes, the NO_DATA_FOUND exception is raised

    B - Select statement returns multiple lines.

    Yes, the TOO_MANY_ROWS exception is thrown

    Max
    [My Italian blog Oracle | http://oracleitalia.wordpress.com/2010/01/17/supporto-di-xml-schema-in-oracle-xmldb/]

    Published by: Massimo Ruocchio, January 19, 2010 17:04
    Added first line

  • Streaming throws Exception of IO interrupted

    I use the Streaming code given at the following link

    http://supportforums.BlackBerry.com/T5/Java-development/streaming-media-start-to-finish/Ta-p/488255

    But when I stop the thread it shows lifted UncaughtException - InterruptedException... ConnectionClosed exception. How to handle?

    I checked the application on the device and works very well. Don't know what problem about Simulator.

    But his works well on the device.

  • Help with the exception of Pl/SQL 'ora-3150 end of file on the communication channel.

    Hello.

    The code attached to this post opens a slider that load of 99 dblinks from different remote databases of different version.

    He captures the information from these databases and stores them locally on a central database (11.2.0.4.0 version) on different tables.

    The problem I have is that when a database is deleted, the dblink to this database show me the error 'ora-3150 end of file on communication channel' and that's right.

    But he's not going trough the exception that I created, the cursor is closed and does not continue with the cycle.

    The exception I created insert data on DBMONITOR error. DBMONITOR_LOG_ERROR_TABLE in order to catch the error (you'll be able to see all the code on the attachment)

    It's the exception:

    exception

    while others then

    INSERT IN DBMONITOR. DBMONITOR_LOG_ERROR_TABLE (NOMBRE_DBLINK, message, info, FECHA_ERROR, TIPO_PROCEDURE) VALUES (var, SUBSTR (DBMS_UTILITY. (FORMAT_ERROR_STACK, 1, 200), "CONNECTION ERROR", SYSDATE, 'CAPACITY');

    commit;

    end;

    Could help me please on how could intercept this exception?

    Thank you.

    Juan.

    You might have a problem with your connection or mishandling. The end of the file ora-3150, on channel of communication error means that there is a connection, but this link was broken somehow.

    If a database is not reachable, you should get other types of errors.

    For example judgment of the Kingdom or tns - memory could not resolve alias or simliar things.

    Here is a list of typical mistakes I have check and manage when accessing remote databases.

      e_db_link_broken EXCEPTION;  --ORA-02019 connection description for remote database not found
      PRAGMA EXCEPTION_INIT (e_db_link_broken, -02019);
      e_oracle_not_available EXCEPTION;  --ORA-01034 ORACLE not available
      PRAGMA EXCEPTION_INIT (e_oracle_not_available, -01034);
      e_oracle_down EXCEPTION;  --ORA-27101: shared memory realm does not exist
      PRAGMA EXCEPTION_INIT (e_oracle_down, -27101);
      e_no_listener EXCEPTION;  --ORA-12541: TNS:no listener
      PRAGMA EXCEPTION_INIT (e_no_listener, -12541);
      e_no_service EXCEPTION;  --ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
      PRAGMA EXCEPTION_INIT (e_no_service, -12514);
      e_timeout EXCEPTION;  --ORA-12170: TNS:Connect timeout occurred
      PRAGMA EXCEPTION_INIT (e_timeout, -12170);
    

    If you have a long open session and fail to close the db links after recovered information from the remote site?

    In addition, I propose to change your dynamic insertion in a normal insert.

    First extract the data of the DB link dynamically, but just with a select statement. Then do the insertion with the result data.

    Improve your logging table to store messages up to 4000 char CHARACTER. 200 is really small for error messages.

    In addition to the DBMS_UTILITY. FORMAT_ERROR_STACK you must also connect DBMS_UTILITY. FORMAT_ERROR_BACKTRACE. Just to see if you get a better message there.

    WHEN e_db_link_broken or e_oracle_not_available or e_oracle_down or e_no_listener or e_no_service or e_timeout THEN
       INSERT INTO DBMONITOR.DBMONITOR_LOG_ERROR_TABLE (NOMBRE_DBLINK, message, info,FECHA_ERROR,TIPO_PROCEDURE) VALUES(var, 'Remote DB not accessible','ERROR DE CONEXION',SYSDATE,'CAPACITY');
                   -- commit;
    WHEN OTHERS THEN
    
                    INSERT INTO DBMONITOR.DBMONITOR_LOG_ERROR_TABLE (NOMBRE_DBLINK, message, info,FECHA_ERROR,TIPO_PROCEDURE) VALUES(var, SUBSTR(DBMS_UTILITY.FORMAT_ERROR_STACK||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE, 1, 4000),'ERROR DE CONEXION',SYSDATE,'CAPACITY');
                    --commit;
                    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;
    

Maybe you are looking for