0

テーブルが空の場合にのみ値をテーブルに挿入するプロシージャを db2 で作成しています。次のステートメントを作成しましたが、エラーが発生しているため、何かが間違っています:

[42601][-104] An unexpected token "END-OF-STATEMENT" was found
following "END FOR". 
Expected tokens may include: " END IF".. SQLCODE=-104, SQLSTATE=42601,
DRIVER=4.7.85

create or REPLACE PROCEDURE proc1
BEGIN
IF (exists (select 1 from table1)) then
TRUNCATE TABLE table1;
ELSE
FOR l1 as
select id, max(bla) as bla from table2 group by id
do
insert into table1 (column1, column2)
values (id, bla);
END FOR;
END IF;
END;

ありがとう!

4

2 に答える 2

0

どうやら、この小さな変更が問題の解決に役立ちました。

create or REPLACE PROCEDURE proc1
BEGIN
IF (exists (select 1 from table1)) then
DELETE FROM TABLE table1;
END IF;
FOR l1 as
select id, max(bla) as bla from table2 group by id
do
insert into table1 (column1, column2)
values (id, bla);
END FOR;
END;
于 2016-12-05T08:05:51.340 に答える
0

なぜあなたはこれだけをしないのですか

create or REPLACE PROCEDURE proc1
BEGIN

DELETE FROM table1;

insert into table1 (column1, column2)
select id, max(bla) from table2 group by id;

END;
于 2016-12-06T06:48:16.060 に答える