Replace CHAR with VARCHAR2

蓝咒 提交于 2019-12-12 16:27:15

问题


How can I replace CHAR with VARCHAR2 in all tables in a schema?

Note: I'm content with a query that returns the ALTER TABLE statements so I can save the script and run it again.


回答1:


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
);


来源:https://stackoverflow.com/questions/2445982/replace-char-with-varchar2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!