If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Need to store SQL error code in debug table

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-09-10, 17:57
surjyakp surjyakp is offline
Registered User
 
Join Date: Jan 2010
Posts: 23
Need to store SQL error code in debug table

Hi,
I have one table having column dbg_lvl and dbg_msg.
Let say i executed some update sql statement in stored perocedure which has some eror. e.g. it threw the error like

SQL0150N The target fullselect, view, typed table, materialized query table,
or staging table in the INSERT, DELETE, UPDATE, or MERGE statement is a target for which the requested operation is not permitted. SQLSTATE=42807

Now I want to store 42807 in dbg_lvl column and the message "SQL0150N The target fullselect, view, typed table, materialized query table,
or staging table in the INSERT, DELETE, UPDATE, or MERGE statement is a target for which the requested operation is not permitted" in dbg_msg column.
Is it possible, if yes then how?

Thanks
Surjya
Reply With Quote
  #2 (permalink)  
Old 02-09-10, 19:51
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 3,283
Check out the SQLSTATE variable and SQLERRM() function in the manual.
Reply With Quote
  #3 (permalink)  
Old 02-09-10, 23:13
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 4,190
Set up an exit handler for this:

CREATE PROCEDURE SP_TEST
(INOUT PARM1 CHAR(1),
INOUT PARM1 CHAR(1),
.
.
OUT DB2_ERROR varchar(1024))
.
.
.
DECLARE EXIT HANDLER FOR SQLEXCEPTION
GET DIAGNOSTICS EXCEPTION 1 DB2_ERROR = MESSAGE_TEXT;

--this one only needed if you want to report warning errors > 0
DECLARE EXIT HANDLER FOR SQLWARNING
GET DIAGNOSTICS EXCEPTION 1 DB2_ERROR = MESSAGE_TEXT;
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On