pianzif的留言板

pianzif 2020-01-02 06:44:32
大家好,这里是我的留言板,如果有问题,欢迎大家留言,我会第一时间进行回复
...全文
79 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
博主你好,看了一篇你讲的SQL Procedure Language的文章,我觉得讲解的非常好,通俗易懂,正好我现在遇到了 一个关于db2自定义函数的问题,现在不知道如何下手,博主有没有空指点一下,或者q我,772532154希望能向博主学习一下sql方便的只是 创建一个自定义函数,传入四个参数l_class,l_fault,l_id,l_type 如果传入的l_id为空则走这边 if l_id is null then 1.查询三张表的数据用union all拼接成一个结果集,获取到符合条件的结果集(不需要返回) 这里需要定义一个类似java的list,将查询出来的结果集加入到list中 select id,name,type,s from ( select id,name,'t1' type,s from t1 where name=l_class union all select id,name,'t2' type,s from t2 where name=l_class union all select id,name,'t3' type,s from t3 where name=l_class ) order by s fetch first 10 rows only 2.如果有数据,那么就遍历结果集(不需要返回) for li in (上面的语句) loop if li.type='t1' and s>=0 then 再次循环,递归查询这张表的所有子数据,通过id查询需要的结果集 WITH RPL (parentid, id, name) AS ( SELECT ROOT.parentid, ROOT.id, ROOT.name FROM t1 ROOT where ROOT.id=li.id UNION ALL SELECT CHILD.parentid, CHILD.id, CHILD.name FROM RPL PARENT, t1 CHILD WHERE PARENT.id= CHILD.parentid ) select RPL.id, RPL.name from RPL for li in (上面的语句) loop select id,title,'t1' type from t4 where itemid=li.id and title like '%l_fault%'(加入到list中) if li.type='t2' and s>=0 then select id,content,'t2' type from t5 where classid=li.id and content like '%l_fault%'(加入到list中) if li.type='t3' and s>=0 then select id,content,'t3' type from t6 where classid=li.id and content like '%l_fault%'(加入到list中) 将这三个结果集拼成一个(list),取前10条返回,则l_id is null分支结束 如果l_id不为null则返回一条结果 if l_id is not null then 1.判断类型,查询不同的表 if l_type = 't1' select conten from xxx where id=l_id(返回一条结果) if l_type = xxx select xxx form xxx where xx=l_id l_id为null分支结束,整个函数流程完成

662

社区成员

发帖
与我相关
我的任务
社区描述
提出问题
其他 技术论坛(原bbs)
社区管理员
  • community_281
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧