oracle 通过参数进行条件更新

qrjkbowd  于 2023-10-16  发布在  Oracle
关注(0)|答案(2)|浏览(131)

我有两个更新声明。它们都更新TOOL_BOX表。我想参数化更新,并根据以下参数化条件将两个更新逻辑合并合并到一个更新语句中。
1.如果PARAMETER表键='Y',则运行下面的更新1。
1.如果PARAMETER表键='N',则运行更新2。
更新1:将数据的子集更新为1

Update tool_box tab1 set col1 = 1
where exists
(select 1 
from
   (select object_name
         max(object_id) object_id
    from tool_box
   group by object_name
   ) x
where x.object_id=tab1.object_id
)

更新2:将整个col1更新为1。

Update tool_box tab1 set col1 = 1
where exists
(select 1 
from dual)
xlpyo6sf

xlpyo6sf1#

看起来对第一次更新的修改应该足以覆盖第二次更新:

Update tool_box tab1 set col1 = 1
where exists
(select 1 
from
   (select object_name
         max(object_id) object_id
    from tool_box
   group by object_name
   ) x
where x.object_id=tab1.object_id
)
or exists (select 1 from parameter where key = 'N');
2lpgd968

2lpgd9682#

假设PARAMETER是一个绑定参数:

Update tool_box tab1 set col1 = 1
where (exists
(select 1 
from
   (select object_name
         max(object_id) object_id
    from tool_box
   group by object_name
   ) x
where x.object_id=tab1.object_id
) )
or :PARAMETER = 'N'

相关问题