必须一个个字段进行, update xxx set a=nvl(a,0), b=nvl(b,0), c=nvl(c,0)
前两个人根本就没理解提问人的意思。 这个可以用过程实现,但执行效率是很低的,该写的就写吧。 假设表名叫table1 sqlstr:='select column_name from user_table_columns where table_name=''table1'''; open col_cur for sqlstr; loop fetch col_cur into v_colname; exit when col_cur%notfound; sqlstr:='update table1 set '||v_colname||'=nvl('||v_colname||',0) where ...'; execute immediate sqlstr; end loop close col_cur;
update xxx set a=nvl(a,0), b=nvl(b,0), c=nvl(c,0)
这个可以用过程实现,但执行效率是很低的,该写的就写吧。
假设表名叫table1
sqlstr:='select column_name from user_table_columns where table_name=''table1''';
open col_cur for sqlstr;
loop
fetch col_cur into v_colname;
exit when col_cur%notfound;
sqlstr:='update table1 set '||v_colname||'=nvl('||v_colname||',0) where ...';
execute immediate sqlstr;
end loop
close col_cur;