PLSQL 用多个集合更新多行
PLSQL Update multiple rows with multiple sets
我有一长串数据需要更新到 table。现在,我明白了如何更新,但是,我很难更新多行。
这是我的示例数据:
Loc Check
020201 10000
020301 10050
020401 10100
020501 10150
020601 10200
我根据在这里找到的内容尝试了不同的方法。但这似乎不是我想要的。
我在想它会是这样的:
UPDATE t1
set check = '10000' where loc = '020201',
set check = '10050' where loc = '020301',
set check = '10100' where loc = '020401'
虽然没用 :D 所以我不知道如何根据多组设置格式...
谢谢。
您可以使用 CASE 表达式
update t1
set check = case loc when '020201' then '10000'
when '020301' then '10100'
... etc.
end
where loc in ('020201','020301',...);
但坦率地说,我只会写几个单例更新语句:
update t1 set check = '10000' where loc = '020201';
update t1 set check = '10100' where loc = '020301';
.etc.
我有一长串数据需要更新到 table。现在,我明白了如何更新,但是,我很难更新多行。
这是我的示例数据:
Loc Check
020201 10000
020301 10050
020401 10100
020501 10150
020601 10200
我根据在这里找到的内容尝试了不同的方法。但这似乎不是我想要的。
我在想它会是这样的:
UPDATE t1
set check = '10000' where loc = '020201',
set check = '10050' where loc = '020301',
set check = '10100' where loc = '020401'
虽然没用 :D 所以我不知道如何根据多组设置格式...
谢谢。
您可以使用 CASE 表达式
update t1
set check = case loc when '020201' then '10000'
when '020301' then '10100'
... etc.
end
where loc in ('020201','020301',...);
但坦率地说,我只会写几个单例更新语句:
update t1 set check = '10000' where loc = '020201';
update t1 set check = '10100' where loc = '020301';
.etc.