RT 谢谢了先
解决方案 »
- Oracle第三方开发工具对比
- 一个让我很郁闷的:character to number conversion error ——求指点
- ORA-04091: 表 HNHF.KCSW 发生了变化, 触发器/函数不能读它
- 触发器替换固定时间
- update table1 set i=i+1 where j in (select id from 游标); 这样不知道可以么,到家帮我看看
- 关于从一个数据库导入数据到令一个数据库
- 关于and / or 的复杂sql语句,向各位大虾请教
- 怎样取得表的表头信息
- 谁有多媒体的处理经验,请求文档!
- 急~请教简单问题~最快时间给分~~
- 高手帮忙,优化SQL
- oracle存储大文件的方法
写了一个你参考一下吧declare
cursor tb is select table_name from user_all_tables ;
table_name varchar2(100);
updatestr varchar2(1000);
colname varchar2(100);
colvalue varchar2(100);
begin
colname:='col1';
open tb;
loop
fetch tb into table_name;
exit when tb%notfound;
updatestr:= 'update '||table_name||' set col1='''||colvalue||'''';
--execute immediate updatestr; --执行update语句
dbms_output.put_line(updatestr);
end loop;
close tb;
end;
有这方法??????
cursor tb is select table_name from user_all_tables ;
type cursor_t is ref cursor;
tableinfo cursor_t;
--cursor tableinfo(tabname) is select column_name,data_type from user_tab_columns where table_name=tabname;
table_name user_tab_columns.TABLE_NAME%type;
updatestr varchar2(4000);
column_name user_tab_columns.COLUMN_NAME%type;
data_type user_tab_columns.data_type%type;
oldstr varchar2(10):='源字符串'; --根据实际情况确定内容和变量长度
newstr varchar2(10):='目标字符串'; --根据实际情况确定内容和变量长度begin open tb;
loop
fetch tb into table_name;
exit when tb%notfound;
open tableinfo for 'select column_name,data_type from user_tab_columns where table_name=:tabname' using table_name;
loop
fetch tableinfo into column_name,data_type;
exit when tableinfo%notfound;
if data_type='VARCHAR2' or data_type='VARCAHR' or data_type='CHAR' then ---可根据需要确定哪些数据类型 updatestr:= 'update '||table_name||' set '||column_name||'= replace('||column_name||','''||oldstr||''','''||newstr||''')';
-- execute immediate updatestr; --确定拼装的SQL无误后可以打开执行update语句
dbms_output.put_line(updatestr); ---可能会报缓冲区满,没有关系,只要看一些前面的update语句是否正确。正式执行时注释掉 end if;
end loop;
close tableinfo;
end loop;
close tb;
end;
cursor tb is select table_name from user_all_tables ;
type cursor_t is ref cursor;
tableinfo cursor_t; table_name user_tab_columns.TABLE_NAME%type;
updatestr varchar2(4000);
column_name user_tab_columns.COLUMN_NAME%type;
data_type user_tab_columns.data_type%type;
oldstr varchar2(10):='源字符串'; --根据实际情况确定内容和变量长度
newstr varchar2(10):='目标字符串'; --根据实际情况确定内容和变量长度begin open tb;
loop
fetch tb into table_name;
exit when tb%notfound;
open tableinfo for 'select column_name,data_type from user_tab_columns where table_name=:tabname' using table_name;
loop
fetch tableinfo into column_name,data_type;
exit when tableinfo%notfound; if data_type='VARCHAR2' or data_type='VARCAHR' or data_type='CHAR' then ---可根据需要确定哪些数据类型 updatestr:= 'update '||table_name||' set '||column_name||'= replace('||column_name||','''||oldstr||''','''||newstr||''')';
-- execute immediate updatestr; --确定拼装的SQL无误后可以打开执行update语句
dbms_output.put_line(updatestr); ---可能会报缓冲区满,没有关系,只要看一些前面的update语句是否正确。正式执行时注释掉
end if;
end loop;
close tableinfo; end loop;
close tb;
end;