update當根據條件不同時 更新同一個字段的方法 或多表插入


1.通過存儲過程

循環 傳值

create or replace procedure p_u is
begin
for rs in (select distinct (rks) from rkbz)
loop
update osm_t_arc_customers t
set t.population = rs.rks + 4
where t.code in
(select code
from osm_t_arc_customers
where code in (select rscode from rkbz where rks = rs.rks));
end loop;
end p_u;

2.通過case when then else end

-------更新c1表中rks 當rks=1時 set rks為5 rks=2時 set rks為6 其余的為4

update c1
set rks = (case
when rks = 1 then
5
when rks = 2 then
6
else
4
end);

 

3.多表插入

INSERT ALL
WHEN (id=1) THEN
INTO table_1 (id, name)
values(id,name)
WHEN (id=2) THEN
INTO table_2 (id, name)
values(id,name)
ELSE
INTO table_other (id, name)
values(id, name)
SELECT id,name
FROM a;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM