我有一个表emp(eid,ename,bossid,eloc)我的要求是编写一个程序来显示位于同一位置的所有员工的所有员工及其老板名称(根据给定的参数)一个给定的emp id)。使用“with”子句可以简单地解决上述查询(对于eid = 10),如下所示
with t (id, name, loc, bsid, bsname) as
(select a.eid, a.ename, a.eloc, b.eid, b.ename
from emp a, emp b
where a.bossid = b.eid)
select y.id, y.bsname
from t x, t y
where x.loc = y.loc and <b> x.id = 10;
但是当我编写如下所示的DB2过程时,该过程无法编译,错误为“SQL0104N意外的令牌”,因为“找到了”bsid,bsname)“。”
create or replace procedure test with (
in argid varchar(100),
)
LANGUAGE SQL
COMMIT ON RETURN NO
BEGIN
for rec as (
with t (id, name, loc, bsid, bsname) as
(select a.eid, a.ename, a.eloc, b.eid, b.ename
from emp a, emp b
where a.bossid = b.eid)
select y.id, y.bsname
from t x, t y
where x.loc = y.loc and x.id = **argid**)
do
call dbms_output.put_line('ID = ' || rec.id || ', Name = ' || rec.bsname );
end for;
END
答案 0 :(得分:0)
我不确定这是否是您的实际程序代码:procedure test with (
和**argid**
看起来非常可疑。
如果是,那么你不应该在FOR:
中的SELECT语句周围使用括号BEGIN
for rec as -- parenthesis removed (
with t (id, name, loc, bsid, bsname) as
...
where x.loc = y.loc and x.id = **argid** -- parenthesis removed)