Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3523

SQL handling exception

$
0
0

Hi, Colleagues: I would like to catch the names of tables with exception thrown, for example the tables do not have COLUMN_NAME='A'. The purpose of this exercise is to test if the exception handling can catch all errors. Inspirted by Kishore Babu's Post "Handling Exception in a for Loop" and Florian Preffer's response, I created two stored procedure for this exerices, the second procedure calls the first one in the for cursor. The first precedure: DROP PROCEDURE "SCHEMA_NAME"."LOAD_TABLE_810::inserter1"; CREATE PROCEDURE "SCHEMA_NAME"."LOAD_TABLE_810::inserter1" (IN table_nm nvarchar(256))    LANGUAGE SQLSCRIPT SQL SECURITY INVOKER as Status_Code INTEGER; V_COMMAND NVARCHAR(256); BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN --EXEC 'ROLLBACK'; SELECT ::SQL_error_Code, ::SQL_error_Message, :table_nm from DUMMY; INSERT INTO "ERROR_LOGS" (ERROR_NO,ERROR_CD,ERROR_MSG,TABLE_NM) VALUES (S.NEXTVAL, ::SQL_error_Code,::SQL_error_Message,:table_nm); Status_Code :=1; END;    SELECT * FROM TABLE_NAME  where COLUMN_NAME = 'A';                EXEC 'COMMIT'; Status_Code :=0; END; ------------------------------------------ SECOND procedure will cal the first one --------------------------------------------------------------: DROP PROCEDURE "SCHEMA_NAME"."LOAD_TABLE_810::call_inserter"; CREATE PROCEDURE "SCHEMA_NAME"."LOAD_TABLE_810::call_inserter" LANGUAGE SQLSCRIPT SQL SECURITY INVOKER as BEGIN DECLARE CURSOR c_cursor FOR SELECT DISTINCT TABLE_NAME from "SYS". "M_CS_TABLES" where SCHEMA_NAME in ('SCHEMA_NAME') and LOADED <> 'FULL' GROUP BY TABLE_NAME ORDER BY TABLE_NAME desc; for D as c_cursor DO call "SCHEMA_NAME"."LOAD_TABLE_810::inserter1"(D.TABLE_NAME); end for; END; ----------------------------------------------------------------------------------

I would like to pass D.TABLE_NAME in the second procedure to the "TABLE_NAME" in the first procedure SELECT * FROM TABLE_NAME  where COLUMN_NAME = 'A';. In this way, I can check each table if have such COLUMN The D.TABLE_NAME can be passed as parameter when call the first procedure.However I have not find a way to pass the D.TABLE_NAME to the "TABLE_NAME" in the first procedure. Can anybody help me with it? HANA SQL is new for me. Thank you very much.


Viewing all articles
Browse latest Browse all 3523

Trending Articles



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