468,257 Members | 1,480 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,257 developers. It's quick & easy.

Exception Handling in DB2 UDB

Hi,

Could any one tell that, how to handle the exceptions mainly after the
insert statement.

I am writing a PL SQL Procedure, it must capture the exception if any.
Also I need the error description for that errror.

Regards,
Ravi.

Mar 7 '06 #1
3 9504
Hi,

Even I was trying to catch exceptions and this is what i was trying.
Hope others will chip in with some more EFFECTIVE examples::

CREATE PROCEDURE test ( IN cntry_cde CHAR(2))
SPECIFIC test
LANGUAGE SQL

se: BEGIN

-- Declare return codes

DECLARE ERRORFLAG INTEGER DEFAULT 0;
DECLARE insert_error CONDITION FOR SQLSTATE 'put the error code here';
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INT DEFAULT 0;

DECLARE CONTINUE HANDLER FOR insert_error
BEGIN
SET errorflag = 1;
END;

-- LOGIC

INSERT into test.t_emp VALUES('1,'tariq','IBM DB2 UDB');

IF ERRORFLAG=1 THEN
-- DO SOME THING
END IF;

END se
regards,
tariq

Mar 7 '06 #2
http://www.db2click.com/my_script_di...orHandler.html

shows one approach to handle exception and continue circumstances

HTH

Sathyaram

Mar 7 '06 #3
rAinDeEr wrote:
Hi,

Even I was trying to catch exceptions and this is what i was trying.
Hope others will chip in with some more EFFECTIVE examples::

CREATE PROCEDURE test ( IN cntry_cde CHAR(2))
SPECIFIC test
LANGUAGE SQL

se: BEGIN

-- Declare return codes

DECLARE ERRORFLAG INTEGER DEFAULT 0;
DECLARE insert_error CONDITION FOR SQLSTATE 'put the error code here';
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INT DEFAULT 0;

DECLARE CONTINUE HANDLER FOR insert_error
BEGIN
SET errorflag = 1;
END;

-- LOGIC

INSERT into test.t_emp VALUES('1,'tariq','IBM DB2 UDB');

IF ERRORFLAG=1 THEN
-- DO SOME THING
END IF;

END se

Tariq,

Why don't you "do something" inside the handler iteslef (that's why it's
called a handler :-)

also note that handlers can (and typically should be specific to teh
statement:
BEGIN
DECLARE .. HANDLER FOR SQLSTATE ....
BEGIN
-- do something
END
INSERT ....
END

It's like Java try... catch
Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by adi | last post: by
6 posts views Thread by Daniel Wilson | last post: by
3 posts views Thread by Master of C++ | last post: by
2 posts views Thread by tom | last post: by
9 posts views Thread by C# Learner | last post: by
44 posts views Thread by craig | last post: by
41 posts views Thread by Zytan | last post: by
1 post views Thread by George2 | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.