7

Explicit Exception creation using SIGNAL, DESIGNAL and handling in HANA procedur...

 2 years ago
source link: https://blogs.sap.com/2022/05/31/explicit-exception-creation-using-signal-designal-and-handling-in-hana-procedures./
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
May 31, 2022 1 minute read

Explicit Exception creation using SIGNAL, DESIGNAL and handling in HANA procedures.

In last session I have discussed about the normal exception handing using EXIT HANDLER .

In today’s session I will discuss about the explicit creation of exception handling using Signal and Condition.

Using our HANA procedure we will check for valid Email ID. If email id is not valid we will signal an exception using condition.

1. Create the below procedures :

Crated a procedure in which first define the signal as condition and declare a exception handler using signal and the validate the email ID –

CREATE PROCEDURE "SE_DEV"."DEMO_WITH_SIGNAL_EXCEPTION" (
        IN emai_id nvarchar(50),
        OUT display_message nvarchar(300) )
    LANGUAGE SQLSCRIPT
    SQL SECURITY INVOKER /* you can set it as DEFINER */
    AS
BEGIN
/* Declaration of Exit Handler */

DECLARE SIG_HANDLER CONDITION FOR SQL_ERROR_CODE 12001;
DECLARE EXIT HANDLER FOR SIG_HANDLER
BEGIN
  display_message := 'Error Code ' || ::SQL_ERROR_CODE || ' ' || ::SQL_ERROR_MESSAGE;
END;

/* Declaration End */

IF :emai_id <> '' AND :emai_id NOT LIKE '_%@__%.__%' THEN

    SIGNAL SIG_HANDLER SET MESSAGE_TEXT = 'Not an Email id';
END if;

display_message := 'Vaild Email Id';

END;

2. Call the procedure using a Valid email ID –

CALL “SE_DEV”.”DEMO_WITH_SIGNAL_EXCEPTION”(‘[email protected]’, ?);

Exception-1.png

3.  Call the procedure using a Invalid email ID  throw the explicit exception and produce the following output –

Calling code – CALL “SE_DEV”.”DEMO_WITH_SIGNAL_EXCEPTION”(‘demo123gmailcom’, ?);

Result –

Exception-2.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK