我使用 Toad For DB2在 DB2 中创建了这个存储过程。
CREATE OR REPLACE PROCEDURE TEST_PROC
BEGIN
DECLARE GLOBAL TEMPORARY TABLE TEMP_TABLE_1(ID INT GENERATED ALWAYS AS IDENTITY,col001 CHAR(36)) NOT LOGGED WITH REPLACE;
DECLARE GLOBAL TEMPORARY TABLE TEMP_TABLE_2(ID INT GENERATED ALWAYS AS IDENTITY,col001 CHAR(36)) NOT LOGGED WITH REPLACE;
DECLARE GLOBAL TEMPORARY TABLE TEMP_TABLE_3(ID INT GENERATED ALWAYS AS IDENTITY,col001 CHAR(36)) NOT LOGGED WITH REPLACE;
INSERT INTO SESSION.TEMP_TABLE_1(col001) VALUES ('TABLE_1_ROW_1');
INSERT INTO SESSION.TEMP_TABLE_1(col001) VALUES ('TABLE_1_ROW_2');
INSERT INTO SESSION.TEMP_TABLE_1(col001) VALUES ('TABLE_1_ROW_3');
INSERT INTO SESSION.TEMP_TABLE_1(col001) VALUES ('TABLE_1_ROW_4');
INSERT INTO SESSION.TEMP_TABLE_2(col001) VALUES ('TABLE_2_ROW_1');
INSERT INTO SESSION.TEMP_TABLE_2(col001) VALUES ('TABLE_2_ROW_2');
INSERT INTO SESSION.TEMP_TABLE_2(col001) VALUES ('TABLE_2_ROW_3');
INSERT INTO SESSION.TEMP_TABLE_3(col001) VALUES ('TABLE_3_ROW_1');
BEGIN
DECLARE temp_cursor CURSOR WITH RETURN TO CLIENT FOR
SELECT tmp.* FROM(
SELECT id, col001 from SESSION.TEMP_TABLE_1
)tmp
Left join SESSION.TEMP_TABLE_2 tmp2 ON tmp2.id = tmp.id
AND EXISTS (SELECT 1 FROM SESSION.TEMP_TABLE_3 t3 WHERE t3.ID = 2);
OPEN temp_cursor;
END;
END;
但执行此存储过程Call TEST_PROC()
会产生错误。
DB2数据库错误:错误[56098] [IBM] [DB2 / NT64] SQL0727N隐式系统操作类型" 5"期间发生错误。为错误返回的信息包括SQLCODE" -338",SQLSTATE" 42972"和消息令牌""。 SQLSTATE = 56098
如果我
,它不会给出任何错误Left Join
更改为INNER JOIN
AND EXISTS (SELECT 1 FROM SESSION.TEMP_TABLE_3 t3 WHERE t3.ID = 2)
但这两个是必需的。
知道我做错了什么吗?