一个存储过程,欢迎进入!

IWE 2014-10-28 11:15:25
表1:org
字段:用户名 org_id,状态 status (字段值包括20、30、40)

表2:user
字段:用户名 user_id,是否有效 active_flag(字段值包括0、1)

表说明:org表是从人力系统取员工是否在岗信息;user表是A系统用户明细表。

实现功能: 根据org表org_id判断 user表user_id是否存在离职或返聘的人员信息,如果org表status值为20或30,那么将user表的active_flag值设为1;如果org表status值为40,那么将user表的active_flag值设为0

欢迎各路大侠亮招!
...全文
164 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
CT_LXL 2014-10-28
  • 打赏
  • 举报
回复
引用 楼主 u010696878 的回复:

merge into user t1
using org t2
on (t2.org_id = t1.user_id)
when matched then
  update set t1.active_flag = decode(t2.status, 20, 1, 30, 1, 0);

bw555 2014-10-28
  • 打赏
  • 举报
回复
update user set active_flag=(
case 
when exists(select 1 from org where org_id=user.user_id and status in (20,30)) then 1
when exists(select 1 from org where org_id=user.user_id and status=40) then 0
end
)
where exists (select 1 from org where org_id=user.user_id and status in (20,30,40))
IWE 2014-10-28
  • 打赏
  • 举报
回复
引用 9 楼 bw555 的回复:
算了你还是用我1楼的case when吧 百度下merge into的用法,好多讲解的
嗯,这个是可行的!
bw555 2014-10-28
  • 打赏
  • 举报
回复
bw555 2014-10-28
  • 打赏
  • 举报
回复
算了你还是用我1楼的case when吧 百度下merge into的用法,好多讲解的
IWE 2014-10-28
  • 打赏
  • 举报
回复
引用 2 楼 zlloct 的回复:
[quote=引用 楼主 u010696878 的回复:]

merge into user t1
using org t2
on (t2.org_id = t1.user_id)
when matched then
  update set t1.active_flag = decode(t2.status, 20, 1, 30, 1, 0);

[/quote]这是update和insert合并的吧, 后面不写就不做insert处理了吗? 如果不写的话报错耶 ora--00905缺少关键字
IWE 2014-10-28
  • 打赏
  • 举报
回复
引用 6 楼 bw555 的回复:
不写默认就是不出来
这是update和insert合并的吧, 后面不写就不做insert处理了吗? 如果不写的话报错耶 ora--00905缺少关键字
bw555 2014-10-28
  • 打赏
  • 举报
回复
不写默认就是不出来
IWE 2014-10-28
  • 打赏
  • 举报
回复
引用 4 楼 bw555 的回复:
[quote=引用 3 楼 u010696878 的回复:] [quote=引用 2 楼 zlloct 的回复:] [quote=引用 楼主 u010696878 的回复:]

merge into user t1
using org t2
on (t2.org_id = t1.user_id)
when matched then
  update set t1.active_flag = decode(t2.status, 20, 1, 30, 1, 0);

[/quote] 最后得加where条件吧[/quote] 他这是merge into的写法,match条件在on 后面写了[/quote]那应该再加一个when not matched then [不做处理] 吧
bw555 2014-10-28
  • 打赏
  • 举报
回复
引用 3 楼 u010696878 的回复:
[quote=引用 2 楼 zlloct 的回复:] [quote=引用 楼主 u010696878 的回复:]

merge into user t1
using org t2
on (t2.org_id = t1.user_id)
when matched then
  update set t1.active_flag = decode(t2.status, 20, 1, 30, 1, 0);

[/quote] 最后得加where条件吧[/quote] 他这是merge into的写法,match条件在on 后面写了
IWE 2014-10-28
  • 打赏
  • 举报
回复
引用 2 楼 zlloct 的回复:
[quote=引用 楼主 u010696878 的回复:]

merge into user t1
using org t2
on (t2.org_id = t1.user_id)
when matched then
  update set t1.active_flag = decode(t2.status, 20, 1, 30, 1, 0);

[/quote] 最后得加where条件吧

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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