17,377
社区成员
发帖
与我相关
我的任务
分享
declare
cursor trim_cursor is
select column_name from user_tab_columns where table_name = 'YONGHU';
trim_col user_tab_columns.COLUMN_NAME%type;
begin
open trim_cursor;
loop
fetch trim_cursor
into trim_col;
EXIT WHEN trim_cursor%NOTFOUND;
update yonghu set trim_col = trim(trim_col);
end loop;
close trim_cursor;
end;
SQL> select sysdate,trim(sysdate),trim(1213.123) from dual;
SYSDATE TRIM(SYSDATE) TRIM(121
------------------- ------------------- --------
2011-09-12 21:34:36 2011-09-12 21:34:36 1213.123
declare
cursor trim_cursor is
select column_name from user_tab_columns where table_name = 'YONGHU';
trim_col user_tab_columns.COLUMN_NAME%type;
v_str varchar2(200);
begin
open trim_cursor;
loop
fetch trim_cursor
into trim_col;
EXIT WHEN trim_cursor%NOTFOUND;
v_str:='update YONGHU set '|| trim_col || '= trim(' ||trim_col ||')';
execute immediate v_str;
--update yonghu set trim_col = trim(trim_col);
end loop;
close trim_cursor;
end;