Quantcast
Channel: SCN: Message List - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 8968

Re: 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:

 

  1. DROP PROCEDURE "SCHEMA_NAME"."LOAD_TABLE_810::inserter1";
  2. CREATE PROCEDURE "SCHEMA_NAME"."LOAD_TABLE_810::inserter1" (IN table_nm nvarchar(256))   
  3. LANGUAGE SQLSCRIPT SQL SECURITY INVOKER as
  4. Status_Code INTEGER; V_COMMAND NVARCHAR(256);
  5. BEGIN
  6. DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN --EXEC 'ROLLBACK';
  7. SELECT ::SQL_error_Code, ::SQL_error_Message, :table_nm from DUMMY;
  8. INSERT INTO "ERROR_LOGS" (ERROR_NO,ERROR_CD,ERROR_MSG,TABLE_NM) VALUES (S.NEXTVAL, ::SQL_error_Code,::SQL_error_Message,:table_nm);
  9. Status_Code :=1;
  10. END;   
  11. SELECT * FROM TABLE_NAME where COLUMN_NAME = 'A';              
  12. EXEC 'COMMIT';
  13. Status_Code :=0;
  14. END;

 

------------------------------------------

 

SECOND procedure will cal the first one

--------------------------------------------------------------:

  1. DROP PROCEDURE "SCHEMA_NAME"."LOAD_TABLE_810::call_inserter";
  2. CREATE PROCEDURE "SCHEMA_NAME"."LOAD_TABLE_810::call_inserter"
  3. LANGUAGE SQLSCRIPT SQL SECURITY INVOKER as
  4. BEGIN
  5. DECLARE CURSOR c_cursor
  6. FOR SELECT DISTINCT TABLE_NAME from "SYS". "M_CS_TABLES"
  7. where SCHEMA_NAME in ('SCHEMA_NAME')
  8. and LOADED <> 'FULL'
  9. GROUP BY TABLE_NAME
  10. ORDER BY TABLE_NAME desc;
  11. for D as c_cursor DO
  12. call "SCHEMA_NAME"."LOAD_TABLE_810::inserter1"(D.TABLE_NAME);
  13. end for;
  14. 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 8968

Trending Articles



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