用VARCHAR2替换CHAR

时间:2010-03-15 09:09:20

标签: oracle replace char varchar2

如何在架构中的所有表中用CHAR替换VARCHAR2

注意:我满足于返回ALTER TABLE语句的查询,因此我可以保存脚本并再次运行。

1 个答案:

答案 0 :(得分:6)

select 'ALTER TABLE "' || owner || '"."' || table_name
|| '" MODIFY ("' || column_name
|| '" VARCHAR2(' || data_length || '));'
from all_tab_columns tc
where data_type = 'CHAR'
and owner = :schemaname
and exists (
    select 1
    from all_tables t
    where tc.owner = t.owner
    and tc.table_name = t.table_name
);