您的位置:程序门 -> db2 -> 数据库开发



db2 存储过程返回结果集问题~~在线求救


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


db2 存储过程返回结果集问题~~在线求救
发表于:2008-01-08 15:19:14 楼主
我在java中调用这个过程。
    在db2中测试这个过程时候报错---下面是过程


create   procedure   hp.p_user_model   (in     username   varchar(50)   )
----------------------------------------------------------------生成db2过程脚本------------------------------
dynamic     result   sets   100
language     sql
reads   sql   data
------------------------------------------------------------------------
--------获得所有模块信息
p1:   begin
declare   cursor1   cursor       with   return     to   client     for
select   *   from   t_model   where   model_id   in(
---根据权限集合获得三级模块id
select   distinct     model_id   from   t_power   where   pw_id   in
--根据角色id在角色权限表中获得权限集合
(select     pw_id   from   t_role_power     where   r_id   in
--根据id在用户角色表中获得角色id
  (   select     r_id     from   t_user_role   where     u_id   in
--根据用户名获得主键id
integer((   select   id   from   t_user   where   username=username)
)
)
)--生成三级级菜单

union   all
select   distinct     m2.parent_model_id   from   t_model   m2   where   m2.model_id   in(
---根据三级模块id集合获得二级级模块id
select   model_id   from   t_power   where   pw_id   in
(select     pw_id   from   t_role_power     where   r_id   in
  (   select     r_id     from   t_user_role   where     u_id   in
integer((   select   id   from   t_user   where   username=username)
)
)
)
)--生成二级级菜单
union   all
select   distinct     m1.parent_model_id   from   t_model   m1   where   m1.model_id   in(
---根据二级模块id集合获得一级级模块id
select   m2.parent_model_id   from   t_model   m2   where   m2.model_id   in(
select   model_id   from   t_power   where   pw_id   in
(select     pw_id   from   t_role_power     where   r_id   in
  (   select     r_id     from   t_user_role   where     u_id   in
integer((   select   id   from   t_user   where   username=username)
)
)
)
)
)--生成一级级菜单
)   ;--获得所有模块信息
------------------------------------------------------------------------
open   cursor1;
end   p1  


----------------运行时错误-------------
p_user_model   -   已更新运行信息。
hp.p_user_model   -   已开始运行。
将结果集中返回的数据限制为前   100   行。
将结果集列中返回的数据限制为前   20   个字节或字符。
hp.p_user_model   -   运行时出现异常:
数据库管理器发生错误。[ibm][cli   driver][db2/nt]   sql0811n     标量全查询、select   ----语句或   values   into   语句的结果有多行。     sqlstate=21000

hp.p_user_model   -   回滚成功完成。
hp.p_user_model   -   运行失败。
-----------------------


select   *   from   t_model   where   model_id   in(

---根据权限集合获得三级模块id

----------省略sql

)   ;--获得所有模块信息

---如果单独运行上面的sql可以得到结果集----


发表于:2008-01-08 15:33:041楼 得分:0
自己顶下,,等待……
发表于:2008-01-09 10:21:572楼 得分:0
declare       cursor1       cursor               with       return           to       client           for  

不需要有to       client吧
发表于:2008-01-11 16:51:423楼 得分:0
to               client           去掉了   还是不行!新手学习!


快速检索

最新资讯
热门点击