Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

Exception Handling

$
0
0

Hi,

 

I have created a stored Procedure which inserts multiple records. I am trying to write exception handling which also reports on the field value which is duplicated.

 

PROCEDURE MYPROC ( ) 
AS
BEGIN
declare j varchar(20) := 25;
 DECLARE EXIT HANDLER FOR SQLEXCEPTION   INSERT INTO  MyErrorTable values (::SQL_ERROR_CODE, ::SQL_ERROR_MESSAGE, :j);
j := :j + 1;
INSERT INTO  MyTable values (:j,'A','A','A','A');
j := :j + 1;
INSERT INTO  MyTable  values (:j,'B','B','B','B');
INSERT INTO MyTable   values (:j,'B','B','B','B');
j := :j + 1;
INSERT INTO  MyTable  values (:j,'C','C','C','C');
END;

MyTable has the first column as key field which is Integer. In the above code, the 3rd insert statement will fail as there would be a unique constraint violated. I would like to know how we can capture that value into the Error Table.

 

When I run the above procedure the value of J is always 25 in the errorTable.

 

Thanks,

Murali.


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>