有兩個表A,B ,根據倆個表身份證欄位a2,b2相等的條件,改變B表b3欄位的值,固定改成1,只要是相等的就改成1。這個存盤程序怎么寫, 沒接觸過寫存盤程序,不知道怎么撰寫。資料量有20000多條吧 ,最好優化些的!
uj5u.com熱心網友回復:
其實不用寫成存盤程序,SQL陳述句可以搞定:
--1.資料量不大時,使用update
update b
set b.b3 = 1
where exists(select null from a where a.a2 = b.b2);
commit;
--2.資料量大時,使用 merge into
merge into b using a on b.b2 = a.a2
when matched then
set b.b3 = 1;
commit;
uj5u.com熱心網友回復:
你如果硬要改成存盤程序也可以:
--1.資料量不大時,使用update
create or replace procedure p_test
is
begin
update b
set b.b3 = 1
where exists(select null from a where a.a2 = b.b2);
commit;
end;
--2.資料量大時,使用 merge into
create or replace procedure p_test
is
begin
merge into b using a on b.b2 = a.a2
when matched then
set b.b3 = 1
;
commit;
end;
uj5u.com熱心網友回復:
鑒于你的資料量很小,可以使用update。uj5u.com熱心網友回復:
直接update 更新就好了吧uj5u.com熱心網友回復:
UPDATE B SET B.B3 = 1 WHERE B.B2 IN (SELECT A.A2 FROM A WHERE A.A2 = B2)轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/79247.html
標籤:開發
上一篇:存盤程序
