I'm trying to determine the line in a stored procedure or the last SQL-statement which is causing a warning / not found. As a workaround I'm using temporary variables which I manually set to determine in which part of my stored procedure a warning occurs.
-- Create an ErrorLog table
Create Table SCHEMA.ErrorLog_lrc_test
(
ErrSQLCODE Integer ,
Codepart Char(1),
Type Char(1) ,
MsgText VarChar(1024));
CREATE OR REPLACE PROCEDURE SCHEMA.test_warning(IN divisor INT)
LANGUAGE SQL
BEGIN
-- Define variables
DECLARE codepart_var Char(1);
DECLARE test_INT INT;
-- Define sqlcode
DECLARE SQLCODE INTEGER;
--Define Warning-Handler
DECLARE CONTINUE HANDLER FOR SQLWARNING, NOT FOUND
BEGIN
INSERT INTO SCHEMA.ErrorLog_lrc_test(ErrSQLCODE, Codepart, TYPE, MsgText)
VALUES(SQLCODE, codepart_var, 'W', SYSPROC.SQLERRM(SQLCODE));
END;
-- Set temporary variable to 'a' to get part of code where warning occured
SET codepart_var = 'a';
-- Create Not Found (Sqlcode 100)
INSERT INTO SCHEMA.ErrorLog_lrc_test
SELECT NULL, NULL, NULL, NULL FROM "SYSIBM".SYSDUMMY1
WHERE 1 = 0 ;
END
call SCHEMA.test_warning(0);
SELECT *
FROM SCHEMA.ErrorLog_lrc_test;
I get the following:
ERRSQLCODE | CODEPART | TYPE | MSGTEXT |
---|---|---|---|
100 | a | W | SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. |
I know that for errors there is a function DBMS_UTILITY.FORMAT_ERROR_BACKTRACE that you can use for tracing errors. Unfortunately that function doesn't trace warnings. Also there is a function DBMS_UTILITY.FORMAT_CALL_STACK, but this doesn't work neither.
Is there another/better way to log the specific line or SQL-statement in a stored procedure which is causing a warning / not found?