为什么异常处理程序在下面的示例中不起作用?
db2 => BEGIN
db2 (cont.) => DECLARE YADAMU_INSTANCE_ID VARCHAR(36);
db2 (cont.) => DECLARE FUNCTION_DEFINITION VARCHAR(256);
db2 (cont.) =>
db2 (cont.) => DECLARE CONTINUE HANDLER FOR SQLSTATE '42884' BEGIN
db2 (cont.) => SELECT LEFT(TRANSLATE ( CHAR(BIGINT(RAND() * 10000000000 )), 'abcdef123456789', '1234567890' ),8)
db2 (cont.) => CONCAT '-'
db2 (cont.) => CONCAT LEFT(TRANSLATE ( CHAR(BIGINT(RAND() * 10000000000 )), 'abcdef123456789', '1234567890' ),4)
db2 (cont.) => CONCAT '-'
db2 (cont.) => CONCAT LEFT(TRANSLATE ( CHAR(BIGINT(RAND() * 10000000000 )), 'abcdef123456789', '1234567890' ),4)
db2 (cont.) => CONCAT '-'
db2 (cont.) => CONCAT LEFT(TRANSLATE ( CHAR(BIGINT(RAND() * 10000000000 )), 'abcdef123456789', '1234567890' ),4)
db2 (cont.) => CONCAT '-'
db2 (cont.) => CONCAT LEFT(TRANSLATE ( CHAR(BIGINT(RAND() * 10000000000000 )), 'abcdef123456789', '1234567890' ),12)
db2 (cont.) => INTO YADAMU_INSTANCE_ID
db2 (cont.) => FROM SYSIBM.SYSDUMMY1;
db2 (cont.) => END;
db2 (cont.) =>
db2 (cont.) => SELECT YADAMU.YADAMU_INSTANCE_ID()
db2 (cont.) => INTO YADAMU_INSTANCE_ID
db2 (cont.) => FROM SYSIBM.SYSDUMMY1;
db2 (cont.) =>
db2 (cont.) => SET FUNCTION_DEFINITION = 'CREATE FUNCTION YADAMU.YADAMU_INSTANCE_ID() RETURNS VARCHAR(36) DETERMINISTIC NO EXTERNAL ACTION CONTAINS SQL RETURN ''' CONCAT YADAMU_INSTANCE_ID CONCAT '''';
db2 (cont.) => EXECUTE IMMEDIATE FUNCTION_DEFINITION;
db2 (cont.) => END;
db2 (cont.) => /
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0440N No authorized routine named "YADAMU_INSTANCE_ID" of type "FUNCTION"
having compatible arguments was found. LINE NUMBER=19. SQLSTATE=42884
db2 =>
1条答案
按热度按时间a14dhokn1#
试试这个。
由于每次都要重新创建函数,并且不处理相应的错误,所以当函数存在时,我在函数定义中添加了
OR REPLACE
子句。注意,复合语句的末尾没有;
。