0

A cursor in a procedure selects the SQL queries, runs them, and logs the results in a table. Currently, if the SQL query contains any errors, it will exit the handler and insert the log into the log table. However, I'm attempting to concatenate the error message and the code (VSQL. CODE) into the log database. Few SQLSTATE 42703,42625,07001 error has occurred. Current Output - Error on Procedure : . SQLSTATE: 07001. SQLCODE: -313. MESSAGE: Number of host variables not valid.

Expected Output - Error on Procedure : . SQLSTATE: 07001. SQLCODE: -313. MESSAGE: Number of host variables not valid. Code 102

------**Sample code snippet**----
SET REFERENCEDT = @I_BSNDT ; ---Input param

FOR VSQL AS CUR1 CURSOR FOR 
SELECT CODE, SQL_QUERY,MESSAGE,col2 FROM tablename  
  
DO 
  
IF COALESCE ( VSQL . col2 , '' ) = '' THEN 
  
PREPARE SQL_QUERY FROM VSQL . SQL_QUERY ; 
OPEN CSR2 USING REFERENCEDT ;   

IF **SQLSTATE** <>'00000' 
THEN 
SET @SYS_MSG = 'Validation Query Error '
|| VSQL.CODE 
|| '.' ; 
SIGNAL SQLSTATE '70020' SET MESSAGE_TEXT = @SYS_MSG ; 
END IF;
 
FETCH CSR2 INTO var1 , var2 ;

WHILE SQLSTATE <> '02000' 
DO 
  
INSERT INTO table1 ( REFERENCEDATE ,CODE , ERROR_STATUS ) VALUES 
(  REFERENCEDT , VSQL . CODE, VSQL . MESSAGE ) ; 
FETCH CSR2 INTO var1 , var2 ; 
  
END WHILE ;
CLOSE CSR2 ;
END FOR ;
MRR
  • 83
  • 3
  • 9
  • The max length of a message text you may get with the SIGNAL statement is 70 characters, if that's the problem. If not, then please, describe the problem in more detail. – Mark Barinstein Dec 19 '22 at 19:07

0 Answers0