Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: Handling exception in a for loop

$
0
0

Hello Kishore,

 

I think you did not understand what I tried to explain in my previous answer. Let me try again .

 

I would implement a procedure which does the insert + error handling for a single data record. E.g. here a simplified not complete procedure. You see that it gets a parameter which can be also be used within the exit handler section. So you can insert the values passed also to your error log table.

PROCEDURE "<schema>"."xxx.procedures::inserter"  ( IN i_test nvarchar(256) )   LANGUAGE SQLSCRIPT  SQL SECURITY INVOKER  as
begin  declare exit handler for sqlexception   begin     select ::sql_error_code, ::sql_error_message, :i_test from dummy;   end;  -- do insert
end

A second procedure acts as caller of the first procedure for all data records you wann process. E.g. here an example which processes 10 records of the tables table.

PROCEDURE "<schema>"."xxx.procedures::call_inserter"   LANGUAGE SQLSCRIPT  SQL SECURITY INVOKER  as
begin  declare cursor c_data for select top 10 * from tables;    for row as c_data do    call "<schema>"."xxx.procedures::inserter"(row.table_name);  end for;
end

So each data record will be handled separately. If e.g. the second data record insert fails, an entry in the log is written. But than the caller procedure will call the inserter procedure for the next data record.

 

But consider that the performance will not be the best in such a single data record processing.

 

Best Regards,

Florian


Viewing all articles
Browse latest Browse all 9165

Trending Articles



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