Teradata提高错误

时间:2018-01-19 04:00:53

标签: teradata raise custom-error-handling

我在teradata v16中制作存储过程,要求我提出错误。我可以看到如何使代码捕获错误(见下文),但不能像其他应用程序一样弄清楚如何引发错误。有些人可以告诉我如何引发错误吗?

    BEGIN
  DECLARE SQL_ERR_CDE INTEGER;
  DECLARE SQL_STATE INTEGER;
  DECLARE TMPMSG VARCHAR(133);

L1: BEGIN
      DECLARE EXIT HANDLER FOR SqlException
        BEGIN
          SET SQLERRCDE = SqlCode;
          SET SQLSTTE = SqlState;
          SET SQLMSG = TMPMSG;
          SET SQL_ERR_CDE = SqlCode;
          SET SQL_STATE = SqlState;
          INSERT INTO DW.ERR_STD_PRC_LOG
          VALUES ('DW', 'SP_INDEX_STATS' , 'E' , :SQL_ERR_CDE,:SQL_STATE, :TMPMSG, DATE, TIME);  
        END;

1 个答案:

答案 0 :(得分:0)

你试过ABORT吗?这应该会导致SP调用错误,包含您要包含的任何消息:

ABORT 'Error Message';

https://info.teradata.com/HTMLPubs/DB_TTU_16_00/index.html#page/SQL_Reference/B035-1146-160K/hch1472240804504.html

另外,请看一下如何使用SIGNAL:Teradata: How can I raise an error in a stored procedures