在ORACLE中怎么实现动态列的更新 比如 :我有 a(column_a,column_b,column_c,.....)b(column_a,column_b,column_c,.....)
2张表,a的列与b的列名字都相同,我现在要在b表中更新相关a的数据,如果才能实现类型update b set column=(select column from a where .....)这里的 column 是动态的我建了个临时表c , c内存储了需要更新的列名,请各位高人指点下 谢谢了
2张表,a的列与b的列名字都相同,我现在要在b表中更新相关a的数据,如果才能实现类型update b set column=(select column from a where .....)这里的 column 是动态的我建了个临时表c , c内存储了需要更新的列名,请各位高人指点下 谢谢了
update b set column=(select column from a where column = 游标里的列名)v_colname varchar2(30);cursor c_arear is
select distinct column from copen c_arear;
loop
fetch c_arear into v_colname;
exit when c_arear%notfound;update b set column=(select column from a where column = v_colname)
end loop;
close c_arear;
commit;
楼主自己把这个过程补全吧 到点吃饭去了。
这个最后报错 column无效列名,,咋弄的 下面是我自己写的 create or replace procedure PROC_TEST iscursor cursor_a is --声明游标(将TABLE中的所有A列的值放入游标中)
select bureau_name
from fp_jq_db_b ;
v_id fp_jq_db_b.bureau_name%type; --声明v_id的数据类型
begin
open cursor_a; --打开游标
loop --循环读取游标中的A列的值,并让a=v_id.
fetch cursor_a into v_id;
exit when cursor_a%notfound;--读完退出
update fp_jq_db_zj set column=(select column from fp_jq_db where column=v_id and ZBDM='AU1200' and acct_type=to_char(sysdate -19,'yyyymm'))
where BBTYPE='无线市话';end loop; close cursor_a; --关闭游标
end PROC_TEST;
column无效列名 问题肯定是在你的这句话,
update fp_jq_db_zj set column=(select column from fp_jq_db where column=v_id and ZBDM='AU1200' and acct_type=to_char(sysdate -19,'yyyymm'))
你把他循环打印出来 就知道怎么回事了。