oracle表名和列名改成小写,【Oracle】表名/列名,大/小写转换

1、表名,小写转大写。如下:my_test转换MY_TEST

56a656d1c43b0804b888b1a5d3d66a6c.png

bbe9dff4cb9a6b59bb85dadad6dfebc4.png

DECLARE

v_tablename_x VARCHAR2(20);

v_tablename_d VARCHAR2(20);

begin

v_tablename_x:='my_test';

v_tablename_d:='MY_TEST';

execute immediate 'alter table "'||v_tablename_x||'" rename to '||v_tablename_d||'';

exception

when others then

dbms_output.put_line(v_tablename_d||'已存在');

end;

2、列名,小写转大写

4592b79c548236c01ab1b5ebdbe371a0.png

bb46d1a08b1190320eff4ace7057f637.png

2b1b1690faed0afdb588f47069ba7f2f.png

DECLARE

v_tablename_d VARCHAR2(20);

begin

v_tablename_d:='MY_TEST';

for c in (select COLUMN_NAME cn from all_tab_columns where table_name=v_tablename_d) loop

begin

execute immediate 'alter table "'||v_tablename_d||'" rename column "'||c.cn||'" to '||c.cn;

exception

when others then

dbms_output.put_line(v_tablename_d||'.'||c.cn||'已经存在');

end;

end loop;

end;

3、表和列一起,小写转大写

c24402ee544535060e9af6b9a5a26ee6.png

a02e0649306d6c446ddcc52c1555ca18.png

f84f1879c970d4fb734d4f769f014d6d.png

DECLARE

v_tablename_x VARCHAR2(20);

v_tablename_d VARCHAR2(20);

begin

v_tablename_x:='my_test';

v_tablename_d:='MY_TEST';

for c in (select COLUMN_NAME cn from all_tab_columns where table_name=v_tablename_x) loop

begin

execute immediate 'alter table "'||v_tablename_x||'" rename column "'||c.cn||'" to '||c.cn;

exception

when others then

dbms_output.put_line(v_tablename_x||'.'||c.cn||'已经存在');

end;

end loop;

execute immediate 'alter table "'||v_tablename_x||'" rename to '||v_tablename_d||'';

exception

when others then

dbms_output.put_line(v_tablename_d||'已存在');

end;

4、表和列一起,大写转小写

d5f0f07aac30cb633641103d67dc77fb.png

8797db39c0900d6a72f3f83074189ac2.png

DECLARE

v_tablename_x VARCHAR2(20);

v_tablename_d VARCHAR2(20);

begin

v_tablename_x:='my_test';

v_tablename_d:='MY_TEST';

for c in (select COLUMN_NAME cn from all_tab_columns where table_name=v_tablename_d) loop

begin

execute immediate 'alter table '||v_tablename_d||' rename column '||c.cn||' to "'||LOWER(c.cn)||'"';

exception

when others then

dbms_output.put_line(v_tablename_d||'.'||c.cn||'已经存在');

end;

end loop;

execute immediate 'alter table '||v_tablename_d||' rename to "'||v_tablename_x||'"';

exception

when others then

dbms_output.put_line(v_tablename_x||'已存在');

end;

5、列名,大写转小写

eebcd237a2dcc6014aa59c092d1edb61.png

25a6cf99c25b1019f8a6cbf48fe629ce.png

DECLARE

v_tablename_d VARCHAR2(20);

begin

v_tablename_d:='MY_TEST';

for c in (select COLUMN_NAME cn from all_tab_columns where table_name=v_tablename_d) loop

begin

execute immediate 'alter table '||v_tablename_d||' rename column '||c.cn||' to "'||LOWER(c.cn)||'"';

exception

when others then

dbms_output.put_line(v_tablename_d||'.'||c.cn||'已经存在');

end;

end loop;

end;

6、表名,大写转小写

fb2cdf5ceb8aca0d92b227a96a740db1.png

DECLARE

v_tablename_x VARCHAR2(20);

v_tablename_d VARCHAR2(20);

begin

v_tablename_x:='my_test';

v_tablename_d:='MY_TEST';

execute immediate 'alter table '||v_tablename_d||' rename to "'||v_tablename_x||'"';

exception

when others then

dbms_output.put_line(v_tablename_x||'已存在');

end;

标签:begin,end,cn,列名,tablename,VARCHAR2,表名,Oracle,table

来源: https://www.cnblogs.com/xiaostudy/p/14240256.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值