

怎么用游標回圈的將第一個表中醫院名改成第二個表中相同醫院名對應的數字代碼吶!其他方法也行,第一張表有的醫院在第二張是沒有的,不用管就行了
uj5u.com熱心網友回復:
UPDATE T1 SET T1.C=(SELECT T2.A FROM T2 WHERE T2.B=T1.C)
沒建表,大概是這樣。如果關聯不到的,第一張表的C列會更新為空,如果想不為空,可以WHERE加EXISTS條件,或者SET中用NVL函式
uj5u.com熱心網友回復:

可以用SQL陳述句解決的不必用游標。
uj5u.com熱心網友回復:
已經解決了-- Created on 2017/8/2 by 李維俊
declare
-- Local variables here
i integer;
begin
-- Test statements here
declare
cursor cur_cc is select *from test_yzz ;
row_ez11 cur_cc%rowtype ;
v_a varchar2 (20);
v_aa varchar2 (20);
v_aaa varchar2 (20);
v_count number;
masg varchar2(100);
n_1 number;
n_2 number;
n_3 number;
begin
for row_ez11 in cur_cc loop
begin
select count(1) into n_1 from test_yzz2 where B=row_ez11.B;
if n_1 > 0 then
select A into v_a from test_yzz2 where B=row_ez11.B;
update test_yzz set B=v_a where B=row_ez11.B;
end if;
select count(1) into n_2 from test_yzz2 where B=row_ez11.C;
if n_2 > 0 then
select A into v_aa from test_yzz2 where B=row_ez11.C;
update test_yzz set C=v_aa where C=row_ez11.C;
end if;
select count(1) into n_3 from test_yzz2 where B=row_ez11.D;
if n_3 > 0 then
select A into v_aaa from test_yzz2 where B=row_ez11.D;
update test_yzz set D=v_aaa where D=row_ez11.D;
end if;
exception when others then
null;
end;
end loop;
exception when others then
masg:=sqlerrm;
dbms_output.put_line(masg);
end;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/86396.html
標籤:開發
上一篇:分組查詢問題,求大神幫忙。
下一篇:oracle安裝
