Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Capturing ORA errors and inserting into a table.

Re: Capturing ORA errors and inserting into a table.

From: <G.Plivna_at_itsystems.lv>
Date: Wed, 08 May 2002 06:23:26 -0800
Message-ID: <F001.0045B668.20020508062326@fatcity.com>

OK here is an example that is used in one of our web applications It isn't very simple :-)

I modified (deleted) code a little bit. There were also show error procedures that get some info from error messages table and printed that in user friendly format in browser window.

There may be some comments in Latvian, if You don't understand them :-)

Enjoy !

Firstly table specs
CREATE TABLE MCM_ERROR_SETS
 (ERS_ID NUMBER(38,0) NOT NULL
,ERS_TIMESTAMP DATE NOT NULL

 )
/

CREATE TABLE MCM_ERRORS

 (ERR_ID  NUMBER(38,0) NOT NULL

,ERR_ERS_ID NUMBER(38,0) NOT NULL
,ERR_TIMESTAMP DATE NOT NULL
,ERR_USER VARCHAR2(30)
,ERR_SEQUENCE NUMBER(4)
,ERR_ALLOCATION VARCHAR2(60)
,ERR_CODE VARCHAR2(60)
,ERR_MESSAGE VARCHAR2(4000)
,ERR_CALL_STACK VARCHAR2(4000)
,ERR_ERROR_STACK VARCHAR2(4000)
,ERR_IP_ADDRESS VARCHAR2(15)
,ERR_REFERRER VARCHAR2(30)
,ERR_DESCRIPTION VARCHAR2(4000)
,ERR_MESSAGE_CODE VARCHAR2(20)
,ERR_ACTION_CODE VARCHAR2(20)

 )
/

Main procedure that logs errors is handle, it is called something like that

      EXCEPTION WHEN OTHERS
      THEN

log$errors.handle(v_ref,'log_journal.log.find_slaes_person_id_by_offer_id',
                            'in_ofr_id=' || in_ofr_id || '&v_customer_id='
|| v_customer_id || '&v_sales_id=' || v_sales_id,
                            v_error_rec.success, v_error_rec.error_code,
v_error_rec.error_text);
      END;


CREATE OR REPLACE PACKAGE LOG$ERRORS IS
-- Datastructure Definitions
TYPE ERROR_REC IS RECORD
 (SUCCESS INTEGER(1) := 1
,ERROR_CODE INTEGER(9) := 0
,ERROR_TEXT VARCHAR2(2000) := 'Operation Successful'
);

PROCEDURE INIT;
PROCEDURE FLUSH_QUEUE
 (IN_EMPTY_QUEUE IN BOOLEAN := TRUE
 );

PROCEDURE HANDLE
 (
  p_ref IN VARCHAR2
,IN_MODULE_NAME IN VARCHAR2
,OUT_SUCCESS_IND OUT INTEGER
,OUT_ERROR_CODE OUT INTEGER
,OUT_ERROR_MESSAGE OUT VARCHAR2
,IN_SHOW_MESSAGE IN BOOLEAN DEFAULT FALSE
,IN_MESSAGE IN VARCHAR2 DEFAULT NULL
,IN_ACTION IN VARCHAR2 DEFAULT NULL
,IN_LANGUAGE IN VARCHAR2 DEFAULT NULL

 );

PROCEDURE HANDLE
 (
  p_ref IN VARCHAR2
,IN_MODULE_NAME IN VARCHAR2
,in_description IN VARCHAR2
,OUT_SUCCESS_IND OUT INTEGER
,OUT_ERROR_CODE OUT INTEGER
,OUT_ERROR_MESSAGE OUT VARCHAR2
,IN_SHOW_MESSAGE IN BOOLEAN DEFAULT FALSE
,IN_MESSAGE IN VARCHAR2 DEFAULT NULL
,IN_ACTION IN VARCHAR2 DEFAULT NULL
,IN_LANGUAGE IN VARCHAR2 DEFAULT NULL

 );

CREATE OR REPLACE PACKAGE BODY LOG$ERRORS IS

Gints Plivna
IT Sistmas, Mer?e?a 13, LV1050 Rga
http://www.itsystems.lv/gints/

                                                                                                                                        
                      Denham Eva                                                                                                        
                      <EvaD_at_TFMC.co.za>        To:       Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com>                    
                      Sent by:                 cc:                                                                                      
                      root_at_fatcity.com         Subject:  Capturing ORA errors and inserting into a table.                               
                                                                                                                                        
                                                                                                                                        
                      2002.05.08 13:33                                                                                                  
                      Please respond to                                                                                                 
                      ORACLE-L                                                                                                          
                                                                                                                                        
                                                                                                                                        




Hello List

Hope someone can help.
Trying to write a procedure where an event, such as a insert or update is done.
However I would like to capture any oracle error (ORA-......) that is generated, into a table for instance..
i.e.

DECLARE
    somevars VARCHAR2(10);
BEGIN

      SELECT stuff
             INTO somevars
      FROM testtbl;

     BEGIN
         INSERT INTO anothertbl
          (col1)
         VALUES(somevars);
     EXCEPTION
       WHEN OTHERS
             *take oracle ORA error and do something*
             *like insert it into a error table. Not just Output to screen.
*
     END;

END; Many Thanks
Denham Eva
Oracle DBA
In UNIX Land
On a quiet Night, you can hear the Windows machines reboot.
#####################################################################################

This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal
For more information please visit www.marshalsoftware.com

#####################################################################################

--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Denham Eva
  INET: EvaD_at_TFMC.co.za

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).


y筅~'"jS
kڝاzN
nu楊w{Zx
I_at_ND
Received on Wed May 08 2002 - 09:23:26 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US