CREATE PROCEDURE ERROR()
LANGUAGE SQL
BEGIN
SIGNAL SQLSTATE ‘80000’
SET MESSAGE_TEXT = ‘Customer number is not known’;
END
message_text是用于handle后异常时处理及执行存储过程后屏幕的输出,当产生signal信号时其之前的事物需要提交,要不然会回滚之前发生的一切事物
当执行db2 "call error"时屏幕会输出’Customer number is not known’,sqlstate=80000
对于signal还可以使用函数的写法:
CREATE PROCEDURE ERROR()
LANGUAGE SQL
BEGIN
RAISE_ERROR(‘70001’,‘EDUCLVL has a value greater than 20’);
END