Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2012
    Posts
    8

    Unanswered: DB2 EXCEPTION details

    Hi folks,

    DB2 Version- v9.7.0.3
    OS-AIX64

    I am running some DMLs inside the SP, now I want whatever exception comes should be inserted into a table.



    below are the sample code from SP-



    DECLARE V_SQLSTATE CHAR(5) DEFAULT '00000';

    DECLARE V_SQLCODE INT DEFAULT 0;

    DECLARE SQLCODE INT DEFAULT 0;

    DECLARE SQLstate CHAR(5);

    DECLARE V_INS_QRY_STR varchar(5000);

    DECLARE continue HANDLER FOR SQLEXCEPTION

    SET V_SQLSTATE=SQLSTATE;

    SET V_SQLCODE=SQLCODE;

    insert into ngcore_tmp.a(roll)values(3534534563463465232453252 353);--I made too big, it will produce the exception

    SET V_SQLSTATE=SQLSTATE;

    SET V_SQLCODE=SQLCODE;

    INSERT INTO Rec_Log(SQLCODE,SQLSTATE,SQLERRMC)

    VALUES(V_SQLCODE, V_SQLSTATE,sysProc.sqlerrm(V_SQLCODE));

    Now I am getting error/execption which is to be trapped into a variable V_SQLCODE - DB2 "Database Error: ERROR [22003] [IBM][DB2/AIX64] SQL0413N Overflow occurred during numeric data type conversion. SQLSTATE=22003"

    Right now although I am getting the error but unable to get error number in SQLCODE variable.



    How can we record all the attributes/values like SQLSTATE,SQLCODE etc. of the exception
    Last edited by 2k.pravin; 07-17-12 at 09:21. Reason: Provided OS/Version info

  2. #2
    Join Date
    Apr 2012
    Posts
    1,034
    Provided Answers: 18
    Always post your DB2-version and fixpack, and Operating System name/version/release...

    You need to learn about EXCEPTION handlers...
    See the many samples that IBM provides, in the samples subdirectory of your DB2-server installation...

  3. #3
    Join Date
    Jul 2012
    Posts
    8

    Thanks, OS and Version Info

    DB2 Version- v9.7.0.3
    OS-AIX64

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •