我必须在桌面上更新700行。只用一个查询就可以做到吗?
2个例子:
UPDATE PERSON p SET p.admin = (select usr.iqid from USER usr where usr.userid = 'J072') where upper(person.myid) = '18349';
UPDATE PERSON p SET p.admin = (select usr.iqid from USER usr where usr.userid = 'PU96') where upper(person.myid) = '36895';
答案 0 :(得分:1)
我会把它写成:
UPDATE PERSON p
SET p.admin = (SELECT u.iqid
FROM USER u
WHERE (u.userid = 'J072' AND p.myid = '18349') OR
(u.userid = 'PU96' AND p.myid = '36895')
)
WHERE p.myid IN ('18349', '36895');
请注意,数字不需要upper()
。它通常会妨碍索引的使用。
答案 1 :(得分:0)
选项1。
update person p
set p.admin =
(select usr.iqid
from user usr
where usr.userid = decode(upper(person.myid), '36895', 'PU96', '18349', 'J072'))
where upper(person.myid) = any ('36895', '18349');
选项2。 使用merge语句来避免相关的标量子查询。
选项3。
Update (select ... from person join user) set ...
如果有人拥有外键引用用户。
谷歌"密钥保存视图"。