将CHAR替换为VARCHAR2 [英] Replace CHAR with VARCHAR2

查看:206
本文介绍了将CHAR替换为VARCHAR2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在模式中的所有表中替换 CHAR VARCHAR2

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

注意:我很满意一个返回 ALTER TABLE 语句的查询,所以我可以保存脚本并再次运行。

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

推荐答案

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

这篇关于将CHAR替换为VARCHAR2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆