呵呵,把下面这个改改看行不行,必须确保用户有足够的权限才行
create or replace procedure p_test
is
v_owner varchar2(128);
v_tab varchar2(128);
v_col varchar2(128);
--取出所有的用户表,只要用户创建的
cursor cur_tab is select owner,table_name from all_tables where owner in('创建的所有用户名');
--取出所有用户字段,只要用户创建的
cursor cur_col(l_tab varchar2,l_owner varchar2) is select column_name from all_tab_columns where table_name=l_tab and owner=l_owner;
v_sql varchar2(4000);
begin
--遍历表
for c_tab in cur_tab loop
v_owner:=c_tab.owner;
v_tab:=c_tab.table_name;
--遍历每张表的所有字段,查看是否有值为522600的字段,如果有,更新为522601
open cur_col(v_tab,v_owner);
loop
fetch cur_col into v_col;
exit when cur_col%notfound;
v_sql:='update '||v_owner||'.'||v_tab||' set '||v_col||'=''522601'' where '||v_col||'=(select '||v_col||' from '||v_owner||'.'||v_tab||' where '||v_col||'=''522600'')';
execute immediate v_sql;
end loop;
end loop;
exception
when others then
dbms_output.put_line(SQLCODE||':'||SQLERRM);
end;