How to trap sql errors in a script

Hi,
I have a SQL script where I need to call 5 other SQL scripts. Every of those 5 scripts contain the following code for trapping an sql error:
WHENEVER SQLERROR EXIT sql.sqlcode
whenever oserror exit os.oscode
SET SERVEROUTPUT ON
In the first script that calls the others I put the same code at the begining.
Is it enough for the first script to trap the errors from the others and to show them at runtime?
Thanks

Yes but test it as we do not necessarily know what you want to script to do when an error occurs.

Similar Messages

  • How to trap No_Data_Found error?

    I know how to trap this error in a back-end script:
    BEGIN
    select empno
    into v_empno
    where empno = 9999999; --no such employee
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    However when I use this approach within a trigger in Form 10g, it fails me. I've experimented with DBMS_ERROR_CODE, but so far got nowhere. Can same approach be used in Forms as I'm using above? If not, how should I approach it?
    Thanks a lot!

    You should write something like this......
    declare
      v_empno emp.empno%type;
      begin
          begin
              select empno into v_empno
                       from emp
                       where empno=99999;
              exception
                   when no_data_found
                      then
                          message('no employee found');
          end;
          <any other code >
      end;Greetings...
    Sim

  • How to use SQL() function while writing scripts in BODS 4.0

    How to use SQL() function while writing scripts in BODS 4.0

    Hello,
    I think you want to post your question to the [Data Integration and Data Quality Management|Data Services and Data Quality; forum. This forum is for other BusinessObjects SDK development questions.
    Sincerely,
    Dan Kelleher

  • EA21 feature "Whenever SQL Error Stop Executing Script User Preference"

    Has anyone come across the feature "Whenever SQL Error Stop Executing Script User Preference" in the new 2.1 release. Doesn't seem to be among the items on the new feature list. This has always been a stumbling block for us in terms of adoption.
    The OTN feature request says scheduled for 2.1.
    Thanks

    Well yes, like that you can give up on sqldev all together too, as we got sqlplus... duh.
    Seriously, we were referring to the request accepted for 2.1.
    Thanks for the tip anyway, for sure it will benefit users that don't know it.
    K.

  • How to execute sql-queries through shell scripting in linux?

    How to execute sql-queries through shell scripting in linux?

    http://www.oracle.com/technology/pub/articles/saternos_scripting.html
    Two simple examples:
    #!/usr/bin/env bash
    set_orafra () {
       orafra=`echo 'set heading off
       select name from v$recovery_file_dest;
       exit' | sqlplus -s / as sysdba`
    set_orafra
    echo $orafra
    #!/usr/bin/env bash
    export ORACLE_SID=instance_name
    export ORACLE_HOME=/path_to_oracle_home_directory
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib
    export PATH=/$ORACLE_HOME/bin/$PATH
    $ORACLE_HOME/bin/sqlplus -s <<EOF
    connect scott/tiger@my_instance_name
    INSERT INTO table VALUES (sysdate);
    exit
    EOFEdited by: Markus Waldorf on Sep 17, 2010 12:19 AM

  • How to trap 1843 error. .nOT Valid month..

    This is in my cursor for loop
    mstart_issue := TO_CHAR(to_date(mstart_issue,'YY-MON'),'Mon.YYYY') ;
                   mend_issue := to_char(to_date(mend_issue,'YY-MON'),'Mon.YYYY');
    But it throws 1843 error..
    i Have execptions for finding value error like
    when value_error then
    warn('value error'||moldmembership);
    But i need something to trap the following error ie ..The moment not a valid month error occurs. .It should trap that error
    Like warn('not validm onth'||membershpnumber)
    What shall be the exeption to catch . .the 1843 error...
    Like we got exceptions like when too many rows to catch duplicate records..
    And this is how my end_issue data looks like .. . 10-jul
    12-Aug date in yy-mon format..
    But seems there is error..
    Kindly help..
    Thanks

    susf wrote:
    Hi Thanks i am implementing both part of code.. Thanks ..
    But ..When i use nls_date_language= 'AMERICAN' I see the output of date in some other language in sql
    The output is like this..
    Loka .2010
    Loka .2010
    Loka .2010
    Loka .2010
    Loka .2010
    Loka .2010
    Loka .2010
    Marras.2010
    Marras.2010
    Marras.2010which line below generates the output above?
    Here is the part of my code
    declare
    msno sub.sno%type;
    e;
    mSTART_ISSUE sub.start_issue%type;
    MEND_ISSUE SUB.END_ISSUE%TYPE;
    MCOMMENTS SUB.COMMENTS%TYPE;
    MPCODE SUB.POSTCODE%TYPE;
    mpay_mode sub.pay_mode%type;
    mrmember sub.rmember%type;
    mflag varchar2(1);
    cursor c1 is select * from htmldb_collections     where collection_name = 'CSV_DATA' and c001 != 'SNO';
    invalid_month exception;
    pragma exception_init( invalid_month, -1843 );
    begin     
    mflag := 'N';
              FOR XXX IN C1
                   LOOP
                   begin
    mrmember := xxx.c023;
    mstart_issue := xxx.c019;
    mend_issue := xxx.c020;
                   BEGIN
    IF SUBSTR ( UPPER (mstart_issue)
         , -3
         ) IN ( 'JAN', 'FEB', 'MAR'
              , 'APR', 'MAY', 'JUN'
              , 'JUL', 'AUG', 'SEP'
              , 'OCT', 'NOV', 'DEC'
    THEN
         MSTART_ISSUE := TO_CHAR(to_date(mstart_issue,'YY-MON','NLS_DATE_LANGUAGE=AMERICAN'),'Mon.YYYY') ;
    mflag := 'Y';
    ELSE
         warn('not valid month startissue ' || moldmembership);
    mflag := 'N';
    END IF;
    IF SUBSTR ( UPPER (mend_issue)
         , -3
         ) IN ( 'JAN', 'FEB', 'MAR'
              , 'APR', 'MAY', 'JUN'
              , 'JUL', 'AUG', 'SEP'
              , 'OCT', 'NOV', 'DEC'
    THEN
         mend_issue := to_char(to_date(mend_issue,'YY-MON','NLS_DATE_LANGUAGE=AMERICAN'),'Mon.YYYY');
    mflag := 'Y';
    ELSE
         warn('not valid month endissue ' || moldmembership);
    mflag := 'N';
    END IF;
    exception
    when invalid_month then
    warn('EXCEPTIONnot valid month xx ' || moldmembership);
    END;
    IF mflag = 'Y' then
                   insert into sub (sno,rno,designation,old,start_issue,end_issue,comments,pay_mode,rmember)
                   values
                   (msno,mrno,mdesignation,moldmem e,maddressedas,madd1,
                   madd2,mcounty,mcity,mstate,mcountry,mph_no,memail,mpostcode,mstart_issue,mend_issue,mco );     
    end if;
    exception
    when value_error then
    warn('value error'||moldmembership);
              end;
    END LOOP;
    END;

  • Trapping SQL errors and OS errors

    hi all,
    i'm running a script which exits execution whenever there is a sql error or an os error. Is it possible to trap the sql error or the os error which caused the script to exits and put it into another log file ? Please Help!!!
    Thanks.

    Please define script. Is it a sqlplus script? Do you run it from a Unix shell script? Or a Windows bat file? Is it a pl/sql program? Do you call a stored procedure?
    You can redirect output from your script to a file.
    If you are using sqlpplus, you can use the spool command to log output.
    From a stored procedure, use a combination of the spool command and dbms_output to log error messages.

  • How to troubleshoot SQL error when copying cube

    I was successful in creating Info Package and running it to copy data frin cube  1 to cube2.  However, I get an error when
    Running the package. My source cube has 1.9 million rows. However, Info Package only loaded 30,120 records.  Looking in monitor logs, it shows me following error stack:
    System error in program SAPLRS_EXECPTION and from RS_EXEPTION_TO_MESSAGE
    SQL Error 0
    Unknown error in SQL Interface
    Errors in source system
    When I click on long text button for Unknown error in SQL interface:
    The SQL interface of the application server (DBSL) has reported an unknown error. This error can be caused by:
    - Overflows when aggregated data is read from the database in ABAP.  If this occurs, the definition for the corresponding key figure must be changed.
    - Internal errors
    It seems to be some kind of Overflow error. Is there any way to get  more information on the cause
    Of this erroru2026.
    THANKS A LOT.

    I tried SM50, it shows me all processes, but I still cannot figure how to set developer trace. Following is detailed information on what I am doing in copy of cubes and errors I am getting:
    Subject: Troubleshoot Copy of Cubes
    I have tried to copy several cubes on my BI 7.0 and all of them same error, so I am wondering whether I am doing something fundamentally wrong.
                    System error in program SAPLRS_EXECPTION and from RS_EXEPTION_TO_MESSAGE
                    SQL Error 0
                    Unknown error in SQL Interface
                    Errors in source system
    After error occurs I get following message in mail:
              The error occurred in Extractor.
               Refer to the error message.
                     Procedure
                 How you remove the error depends on the error message.
                     Note
              If the source system is a Client Workstation, then it            is possible that the file that you wanted to load was being edited
    at the time of the data request. Make sure that the file is in
    the specified directory, that it is not being processed at the
    I  looked  in SM21, system logs, whenever error occurs, I see the  u201C
    Database selection with invalid cursor &5&5
    The database interface was called by a cursor (in a FETCH or CLOSE cursor operation) that is not flagged as opened. This can occur if a COMMIT or ROLLBACK was executed within a SELECT loop (which closes all opened cursors), followed by another attempt to access the cursor (for example, the next time the loop is executed).
    I DO NOT UNDERSTAND WHEN I AM COPYING FROM CUBE, WHY SAP BW will  generate u201Cinvalid cursoru201D message. Not sure whether it is normal, i.e., not a real error,
    My cube copying  (from cube 1 to cube 2) is a straightforward procedure:
    a.     Select Copy from Cube 1 and create Cube 2.
    b.     Create Export Data Source from Cube 1 Menu.
    c.     From Cube 2 menu, Create Update rules, In update rules select DataSource as 8Cube1.
    d.     Create an Info Package for 8Cube1 under Infosource/DataSource and then run the package.
    Certain no of records e.g.. 3248 or so get loaded and then the error messages are generated, why?
    Really appreciate any help. I tried SM37, does not give any clue. I also Tried SM50, it shows me the process, but I still cannot figure how to generate developer trace.
    Since behavior is same for several cubes I tried, something else also needs to be done, I do not know what???

  • How to handle sql error exception in view object

    Guys,
             I have view object (with rows fetched from a sql query).
    Say the query in the VO looks like this..
    select plsql_fun(c) from dual
    (Note : the plsql function in the above query can throw an exception in some cases)
    when the plsql function throws a exception, we get sql exception  (oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation)
    Is there any way i can catch this exception and return -1 in the view object...
    Thanks in advance.

    Check out http://www.oracle.com/technetwork/issue-archive/2013/13-mar/o23adf-1897193.html
    Have you tried to surround hte executeQuery  with a try catch block?
    Timo

  • How to access sql server using java script

    Hi, Is it possible to connect to sql server in java script. I'm using microsoft jdbc driver for connectivity to sql server.
    Thanks

    Hi, Is it possible to connect to sql server in java
    script. I'm using microsoft jdbc driver for
    connectivity to sql server.If you want to ask about Javascript, you are in the wrong place. Go and find some JavaScript forum. Actually, you could connect to database from javascript using Ajax or the like mainly because you could have Java code behind the scenes, but then that too is not something I would want to discuss here. So, go find the correct place for the topic.

  • How To Execute SQL Statements From Shell Scripts?

    I need to extecute some SELECT statements from a shell scripts. Could anybody kindly tell me how to do that, or which document i should refer to ? Thank you very much!

    You can execute SQLPlus with the SQL in a file (sqlplus -s @<sql-script>).

  • How to add an error message to script?

    Hi, every one
    I got this script
    function paste in place to next master
    I want to add an error message to it, if there was no such thing as master B, C,D,E,F,G
    instead of system error.
    Teetan
    var
      myDialog = app.dialogs.add({name:"Copy Selected item(s) to chosen Master",canCancel:true}),
      mStringList = ["Master A", "Master B","Master C", "Master D", "Master E","Master F", "Master G"];
    with(myDialog){
      with(dialogColumns.add()){
      staticTexts.add({staticLabel:"Select a Master you want to copy to"});
      with(dialogRows.add()){
      var mySelection = dropdowns.add({stringList:mStringList, selectedIndex:0});
    app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Paste in place");
    function main(){
      if (!app.documents.length || !app.selection.length)
      alert( "Nothing selected!" );
      exit();
      if (myDialog.show() == true)
      copy_to_next_master(); 
    function copy_to_next_master() { 
    var
      mChoice = mySelection.selectedIndex,
      mMsg = "Done.\rWhat you select is pasted in place to next documents - " + mStringList[mChoice],
      nSel = app.selection.length,
      mDone = false,
      i,n,nextDoc,curSel;   
    for ( i = 1; i < app.documents.length; i++) {   
      nextDoc = app.documents[i];   
      targetMaster = nextDoc.masterSpreads[mChoice];
      if (!targetMaster.isValid) {
      mMsg += "\rCan't detect " + mStringList[mChoice] + " in a doc: " + nextDoc.name;
      continue;
      mDone = true;
      for ( n = 0; n < nSel; n++ ) { 
      curSel = app.selection[n]; 
      curSel.duplicate( nextDoc.masterSpreads[mChoice] ); 
    mDone ? alert(mMsg) : alert("Nothing copied");

    Sorry Jarek
    I made a big mistake
    I want add an error message in to this:
    var curSel = app.selection[0]; 
    for ( var i = 1; i < app.documents.length; i++) { 
        var nextDoc = app.documents[i]; 
        if (!curSel) { alert( "Nothing selected!" ); exit(); } 
        curSel.duplicate( nextDoc.masterSpreads[1] ); 
    in case of I just want to paste in place to only on choice
    Teetan

  • Trapping ora- errors in alert.log

    hello everyone,
    A classical question that I think every DBA has encountered.
    We have about 40 oracle database servers, some with 9i, others with 10g, still others with both. Some on Linux, others on Solaris.
    My question is, how to trap ora- errors in the alert.log of these database and having them being sent as an email.
    It's not an easy question to answer, I know. But I'd like to get ideas from your experiences in implementing the same thing in your environments.
    Many thnx.
    Hiruya

    Hi,
    this let you look for errors :
    utl_file.get_line(vInHandle, vNewLine);
    IF vNewLine like ('%ORA-%') then
    Then this let you to mail the errors :
    utl_smtp.mail
    Here is my complete script :
    SET SERVEROUT ON
    DECLARE
    c utl_smtp.connection;
    vInHandle utl_file.file_type;
    vNewLine VARCHAR2(250);
    vMessage VARCHAR2(250);
    I pls_integer := 0;
    LC$Fic_in Varchar2(128) := 'db1ALRT.LOG'; -- a adapter sur votre configuration
    LC$Dir_in Varchar(30) := 'C:\oracle\admin\db1\bdump';
    PROCEDURE send_header(name VARCHAR2, header VARCHAR2) AS
    BEGIN
    utl_smtp.write_data(c,name ||':'|| header || UTL_TCP.CRLF);
    END;
    BEGIN
    vInHandle := utl_file.fopen(LC$Dir_in, LC$Fic_in, 'R');
    LOOP
    BEGIN
    utl_file.get_line(vInHandle, vNewLine);
    IF vNewLine like ('%ORA-%') then
    vMessage:=vMessage||chr(10)||vNewLine;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    EXIT;
    END;
    END LOOP;
    utl_file.fclose(vInHandle);
    -----------------------SEND A MAIL---------------------------
    c := utl_smtp.open_connection(‘smtpserver’,25);
    utl_smtp.helo(c, ‘something.com');
    utl_smtp.mail(c, [email protected]');
    utl_smtp.rcpt(c, ‘[email protected]');
    utl_smtp.open_data(c);
    send_header('From', '"someone" <[email protected]>');
    send_header('To', '"Recipient" < [email protected] >');
    send_header('Subject', 'DB1 ERREUR ALERT LOG');
    utl_smtp.write_data(c, UTL_TCP.CRLF ||vMessage);
    utl_smtp.close_data(c);
    utl_smtp.quit(c);
    EXCEPTION
    WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
    BEGIN
    utl_smtp.quit(c);
    EXCEPTION
    WHEN utl_smtp.transient_error
    OR utl_smtp.permanent_error THEN
    NULL;
    END;
    raise_application_error(-20000, SQLERRM);
    END fopen;
    /

  • Sql*loader in batch script

    Hi,
    I am calling a sqlloader and a procedure within a loop inside a batch script.
    Sometimes, The sqlloader fails and subsequent procedure fails, I am not able move to the next iteration.
    How to catch oracle errors in batch script
    Thx.

    hi,
    My batch script is something like this.
    I want to catch errors when
    1. sql*loader throws error
    2. when my pl/sql throws error.
    I welcome any suggestions to improve this code.
    d:
    echo cd Data\Scripts
    for %%f in (D:\Data\DELIVERY_NOTE\*.csv) Do (
    echo conn config/config;
    echo delete from SQLLOAD_DELIVERY_STAGE;
    )| sqlplus -s /nolog
    sqlldr USERID=config/config control=D:\Data\Scripts\loaddata_del.ctl skip=2 data=%%f
    echo conn config/config;
    echo exec DELIVERY_NOTE_PKG.Populate_Del_Note_stage;
    echo exec DELIVERY_NOTE_PKG.PROCESS_DELIVERY_NOTE;
    )| sqlplus -s /nolog
    move %%f D:\Data\Processed_Delivery\
    cd D:\Data\processed_Delivery\
    rename *.csv *.csv.processed
    cd d:\Data\scripts\
    echo #############
    echo PROCESSED THE FILE %%f AT %data% %time%
    echo ############
    )

  • Trap Oracle error.

    I am using Developer Suite 9i with Oracle 9i as the backend. I have a doubt with trapping Oracle error 'ORA-00054'. For trapping a 'frm' error, say 40401, i write this code:-
    DECLARE
    lv_errtype VARCHAR2(3) := ERROR_TYPE;
    lv_errcod NUMBER := ERROR_CODE;
    lv_errtxt VARCHAR2(80) := ERROR_TEXT;
    BEGIN
    IF lv_errcod = 40401 THEN
    null;
    END IF;
    END;
    But, how to trap this error, say ORA-00054 or any other ORA error. In the back-end, we declare a exception using 'init_pragma(name,error_code)' and handle it.
    In the forms front-end application, Developer Suite 9i, how do i handle that.
    I hope, my question is clear. Please help in solving the doubt as it is urgent.
    Regards.

    thanks for ur update, i was simulating a 'no data found' intentionally, and had written a ON-ERROR trigger at the form level using:-
    DECLARE
    lv_errtype VARCHAR2(3) := ERROR_TYPE;
    lv_errcod NUMBER := ERROR_CODE;
    lv_errtxt VARCHAR2(80) := ERROR_TEXT;
    BEGIN
    IF lv_errcod = 01403 THEN
    message('no data found');
    END IF;
    message(lv_errtype);
    END;
    But, the message 'no data found' is not being raised, 'if' condition is not getting satisfied. In 'ERROR_TYPE', it is showing 'FRM', whereas, i am trying to simulate a database error.

Maybe you are looking for