CREATE PROCEDURE skygetkey
(
IN "KEY" varchar(50),
OUT "RETVAL" INTEGER
)
LANGUAGE SQL
NOT DETERMINISTIC
EXTERNAL ACTION
MODIFIES SQL DATA
CALLED ON NULL INPUT
INHERIT SPECIAL REGISTERS
BEGIN
IF Exists(SELECT name FROM skykeys WHERE name=KEY)
THEN
SELECT RETVAL=VALUE FROM skykeys WHERE name = KEY;
SET RETVAL = isnull(RETVAL, 0) +1;
UPDATE skykeys SET value = RETVAL WHERE name = KEY;
ELSE
INSERT INTO skykeys VALUES(KEY, 1);
SET RETVAL = 1;
END IF;
END
提示错误:
DB2 Database Error:
ERROR [42601] [IBM][DB2/LINUX] SQL0104N An unexpected token "SELECT" was found following "E name=KEY) THEN ".
Expected tokens may include: "SET". LINE NUMBER=15. SQLSTATE=42601。
其中skykeys表只有两个字段name,value两个字段。