在SAP HANA程序中退出HANDLER例外

时间:2017-11-03 09:15:15

标签: sap hana

在SAP HANA中,我试图在单独的表中捕获错误日志,但我不能......

这是我的代码

create procedure "KABIL_PRACTICE"."PROC_ADV_SALES_INVENTORY"
 (
IN "P_ID" integer,
IN "P_NAME" nvarchar(35),
IN "QTY" integer, 
OUT Result "KABIL_PRACTICE"."TT_SALES_PRODUCT_INVENTORY")
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
as begin        LANGUAGE SQLSCRIPT
        SQL SECURITY INVOKER
    as begin
    declare PROD_ID integer;
    declare INV integer;
    declare Q integer;
    declare EP decimal (34,2);
    declare SALES_AMOUNT Decimal(34,2);
    select count(*) into PROD_ID from "KABIL_PRACTICE"."PRODUCT_ITEM_PROC" where "P_ID" = :P_ID;
    select "Stock" into INV from "KABIL_PRACTICE"."PRODUCT_MASTER_PROC"  where "P_ID" = :P_ID;
    select "USP" into EP from "KABIL_PRACTICE"."PRODUCT_ITEM_PROC"  where "P_ID" = :P_ID;
     IF PROD_ID = 0 THEN
     DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
    insert into "KABIL_PRACTICE"."ERROR_LOG" values (::SQL_ERROR_CODE,::SQL_ERROR_MESSAGE);
    select * from "KABIL_PRACTICE"."ERROR_LOG";
    END;
     ELSE IF INV >= :QTY THEN
    SALES_AMOUNT := (:QTY * :EP);
    insert into "KABIL_PRACTICE"."SALES_PROC" ("P_ID","P_NAME","QTY","Sales_AMount","Time_Of_Sale") values (:P_ID,:P_NAME,:QTY,:SALES_AMOUNT,CURRENT_TIMESTAMP);
    update "KABIL_PRACTICE"."PRODUCT_MASTER_PROC" set "Stock" = "Stock"- :QTY where  "P_ID" = :P_ID;
    Result = select "S_ID","P_ID","P_NAME","QTY","Sales_AMount" from "KABIL_PRACTICE"."SALES_PROC";
    END IF;
    END IF;
    end;

但退出处理程序异常的相同代码在我的另一个过程中工作,这就是代码:

        CREATE PROCEDURE "KABIL_PRACTICE"."EXCEPTION_EXAMPLE2" (
            IN ip_id integer,
            IN ip_name nvarchar(40),
            OUT ex_message nvarchar(200) )
        LANGUAGE SQLSCRIPT
        SQL SECURITY INVOKER
        AS
    BEGIN
    declare E integer;

    DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
    E := ::SQL_ERROR_CODE;
    insert into "KABIL_PRACTICE"."ERROR_LOG" values 
    (:E,::SQL_ERROR_MESSAGE);
      ex_message := 'SQL Exception occured. Error Code is: ' || 
     ::SQL_ERROR_CODE || ' Error message is: ' || ::SQL_ERROR_MESSAGE;
    END;
    INSERT INTO "KABIL_PRACTICE"."ERROR_TEST" VALUES( :ip_id, :ip_name);
    ex_message := 'Product "' || :ip_id || '" inserted successfully'; 
    END;

我的疑问是我的条件是否正确......或者该代码的位置是否正确不是.. ????

1 个答案:

答案 0 :(得分:0)

我认为异常声明就像参数声明应该在SQL代码

之前发生