DB2 PL / SQL结构,包括查询开始原子

时间:2018-04-15 04:17:51

标签: sql plsql db2

我正在尝试使用db2 pl / sql脚本来提供模板代码。

--#set delimiter !

begin atomic

for S as
<query statement that finds quests, "swaps", with a donor/donation &     recipient pair>

do
<update statement that fixes Loot with the swap 'S'>;

end for;
-- handle each swap

end!
-- we're done once through

在我的查询语句中,我使用了这样的东西:

with
   t1 (args) as (
   ...
   )
   ...
   select ...
   where ... ;
更新声明中的

update Loot set ... where ...

但问题是,当我尝试在数据库上运行完整的sql代码脚本时,我不断收到消息:

"An unexpected token "begin" was found following "<identifier>". 
Expected tokens may include: "USER". SQLSTATE=42601 DB21007E End of file 
reached while reading the command.

我想知道,如何使用正确的语法或格式来包含“with queries”以及更新语句以停止向我提供错误。我在一个单独的文件中使用“with query”,但是当我将两个语句组合到模板中时,它会给我这个错误。另外,如果我要包含触发器,我应该把它放在哪部分代码中。谢谢。

1 个答案:

答案 0 :(得分:0)

这是一个可能有帮助的例子。

CREATE TABLE EG(I INT, J INT)!
INSERT INTO EG VALUES (1,1),(2,3)!
begin
    for c as with w(i,u) as(values (2,5)) select i,u from w
    do
        update eg set j = j + c.u where i = c.i;
    end for;
end
!

如果这对您的问题没有帮助,请发布我们可以运行的代码版本,并返回您正在努力解决的错误消息。