有什么方法能将oracle中CHAR类型数据中的空
1个回答
展开全部
可以用脚本把CHAR类型字段全部转换成VARCHAR2类型,同时截掉字符串的空格,如下:
declare
begin
for c in (select *
from user_tab_columns t1
where t1.DATA_TYPE = 'CHAR'
) loop
execute immediate 'alter table ' || c.table_name || ' add g_w_' || c.column_name || ' varchar2(' || c.char_length || ')';
execute immediate 'update ' || c.table_name || ' set g_w_' || c.column_name || ' = ' || c.column_name;
execute immediate 'update ' || c.table_name || ' set ' || c.column_name || ' = null';
execute immediate 'alter table ' || c.table_name || ' modify ' || c.column_name || ' varchar2(' || c.char_length || ')';
execute immediate 'update ' || c.table_name || ' set ' || c.column_name || ' = trim(g_w_' || c.column_name || ')';
execute immediate 'alter table ' || c.table_name || ' drop column g_w_' || c.column_name;
end loop;
end;
declare
begin
for c in (select *
from user_tab_columns t1
where t1.DATA_TYPE = 'CHAR'
) loop
execute immediate 'alter table ' || c.table_name || ' add g_w_' || c.column_name || ' varchar2(' || c.char_length || ')';
execute immediate 'update ' || c.table_name || ' set g_w_' || c.column_name || ' = ' || c.column_name;
execute immediate 'update ' || c.table_name || ' set ' || c.column_name || ' = null';
execute immediate 'alter table ' || c.table_name || ' modify ' || c.column_name || ' varchar2(' || c.char_length || ')';
execute immediate 'update ' || c.table_name || ' set ' || c.column_name || ' = trim(g_w_' || c.column_name || ')';
execute immediate 'alter table ' || c.table_name || ' drop column g_w_' || c.column_name;
end loop;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询