oracle通过存储过程实现表间字段迁移
oracle通过存储过程实现表间字段迁移
条件:
两个表:
ITPUB_TEST1 字段 id,value
ITPUB_TEST2 字段 id,funcid ,action
ITPUB_TEST2 的funcid 关联ITPUB_TEST1 中的id。
任务:
将ITPUB_TEST2 中的action内容 迁移到对应ITPUB_TEST1的value字段。(funcid对应id)
[sql]
create or replace procedure transfer as
Cursor cursor is select funcid,action from ITPUB_TEST2;
myVar varchar2(50);
begin
for myVar in cursor LOOP
begin
dbms_output.put_line(myVar.funcid);
dbms_output.put_line(myVar.action);
if(myVar.funcid != 0) then
dbms_output.put_line('ok');
update ITPUB_TEST1 set value=myVar.action where id=myVar.funcid;
end if;
end;
end LOOP;
commit;
end;
[sql]
[sql]
执行:
[sql]
exec transfer();
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。