Oracle修改字段顺序和字段类型以及拼接字段,查看锁表
2016-08-17 00:00
489 查看
字段有数据,则类型不能直接rename
/*增加一个新字段sub_pol_code*/
alter table IPR_SUB_POLICY add sub_pol_code VARCHAR2(8);
/*将原字段ORDER_SEQ数据更新到增加的字段sub_pol_code*/
update IPR_SUB_POLICY set sub_pol_code=trim(ORDER_SEQ);
/*更新完,删除原字段ORDER_SEQ*/
alter table IPR_SUB_POLICY drop column ORDER_SEQ;
将字段
拼接为qwe-1
update IPR_SUB_POLICY set sub_pol_code= CONCAT(CONCAT(pol_code,'-'),sub_pol_code) where sub_pol_id>=1818
select * from sys.col$ where obj#=88368;
select * from all_objects where owner = 'PRODUCT' and object_name = 'IPR_SUB_POLICY' ;
select obj#,col#,name from sys.col$ where obj#=88368;
update sys.col$ set col#=7 where obj#=88368 and name='SUB_POL_CODE';
update sys.col$ set col#=3 where obj#=88368 and name='SUB_POL_NAME';
update sys.col$ set col#=4 where obj#=88368 and name='CREATE_DATE';
update sys.col$ set col#=5 where obj#=88368 and name='SALE_SERVE_OPTION';
update sys.col$ set col#=6 where obj#=88368 and name='APPLY_TYPE_CODE';
[test@rhel675771 ~]$ sqlplus sys/Clic1234 as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on 星期三 8月 17 17:15:31 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> update sys.col$ set col#=3 where obj#=88368 and name='SUB_POL_CODE'
2
SQL> select obj#,col#,name from sys.col$ where obj#=88368;
OBJ# COL# NAME
---------- ---------- ------------------------------
88368 1 SUB_POL_ID
88368 2 POL_CODE
88368 3 SUB_POL_NAME
88368 4 CREATE_DATE
88368 5 SALE_SERVE_OPTION
88368 6 APPLY_TYPE_CODE
88368 7 SUB_POL_CODE
7 rows selected.
SQL> update sys.col$ set col#=3 where obj#=88368 and name='SUB_POL_CODE';
1 row updated.
SQL> select obj#,col#,name from sys.col$ where obj#=88368;
OBJ# COL# NAME
---------- ---------- ------------------------------
88368 1 SUB_POL_ID
88368 2 POL_CODE
88368 3 SUB_POL_NAME
88368 4 CREATE_DATE
88368 5 SALE_SERVE_OPTION
88368 6 APPLY_TYPE_CODE
88368 3 SUB_POL_CODE
7 rows selected.
SQL> update sys.col$ set col#=4 where obj#=88368 and name='SUB_POL_NAME';
1 row updated.
SQL> update sys.col$ set col#=5 where obj#=88368 and name='CREATE_DATE';
1 row updated.
SQL> update sys.col$ set col#=6 where obj#=88368 and name='SALE_SERVE_OPTION';
1 row updated.
SQL> update sys.col$ set col#=7 where obj#=88368 and name='APPLY_TYPE_CODE';
1 row updated.
SQL> select obj#,col#,name from sys.col$ where obj#=88368;
OBJ# COL# NAME
---------- ---------- ------------------------------
88368 1 SUB_POL_ID
88368 2 POL_CODE
88368 4 SUB_POL_NAME
88368 5 CREATE_DATE
88368 6 SALE_SERVE_OPTION
88368 7 APPLY_TYPE_CODE
88368 3 SUB_POL_CODE
7 rows selected.
SQL> commit;
Commit complete.
select * from v$locked_object x , dba_objects m where x.OBJECT_ID=m.OBJECT_ID
select * from v$session where sid=3428
alter system kill session '3428,3249'--sid ,serial#
/*增加一个新字段sub_pol_code*/
alter table IPR_SUB_POLICY add sub_pol_code VARCHAR2(8);
/*将原字段ORDER_SEQ数据更新到增加的字段sub_pol_code*/
update IPR_SUB_POLICY set sub_pol_code=trim(ORDER_SEQ);
/*更新完,删除原字段ORDER_SEQ*/
alter table IPR_SUB_POLICY drop column ORDER_SEQ;
将字段
拼接为qwe-1
update IPR_SUB_POLICY set sub_pol_code= CONCAT(CONCAT(pol_code,'-'),sub_pol_code) where sub_pol_id>=1818
select * from sys.col$ where obj#=88368;
select * from all_objects where owner = 'PRODUCT' and object_name = 'IPR_SUB_POLICY' ;
select obj#,col#,name from sys.col$ where obj#=88368;
update sys.col$ set col#=7 where obj#=88368 and name='SUB_POL_CODE';
update sys.col$ set col#=3 where obj#=88368 and name='SUB_POL_NAME';
update sys.col$ set col#=4 where obj#=88368 and name='CREATE_DATE';
update sys.col$ set col#=5 where obj#=88368 and name='SALE_SERVE_OPTION';
update sys.col$ set col#=6 where obj#=88368 and name='APPLY_TYPE_CODE';
[test@rhel675771 ~]$ sqlplus sys/Clic1234 as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on 星期三 8月 17 17:15:31 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> update sys.col$ set col#=3 where obj#=88368 and name='SUB_POL_CODE'
2
SQL> select obj#,col#,name from sys.col$ where obj#=88368;
OBJ# COL# NAME
---------- ---------- ------------------------------
88368 1 SUB_POL_ID
88368 2 POL_CODE
88368 3 SUB_POL_NAME
88368 4 CREATE_DATE
88368 5 SALE_SERVE_OPTION
88368 6 APPLY_TYPE_CODE
88368 7 SUB_POL_CODE
7 rows selected.
SQL> update sys.col$ set col#=3 where obj#=88368 and name='SUB_POL_CODE';
1 row updated.
SQL> select obj#,col#,name from sys.col$ where obj#=88368;
OBJ# COL# NAME
---------- ---------- ------------------------------
88368 1 SUB_POL_ID
88368 2 POL_CODE
88368 3 SUB_POL_NAME
88368 4 CREATE_DATE
88368 5 SALE_SERVE_OPTION
88368 6 APPLY_TYPE_CODE
88368 3 SUB_POL_CODE
7 rows selected.
SQL> update sys.col$ set col#=4 where obj#=88368 and name='SUB_POL_NAME';
1 row updated.
SQL> update sys.col$ set col#=5 where obj#=88368 and name='CREATE_DATE';
1 row updated.
SQL> update sys.col$ set col#=6 where obj#=88368 and name='SALE_SERVE_OPTION';
1 row updated.
SQL> update sys.col$ set col#=7 where obj#=88368 and name='APPLY_TYPE_CODE';
1 row updated.
SQL> select obj#,col#,name from sys.col$ where obj#=88368;
OBJ# COL# NAME
---------- ---------- ------------------------------
88368 1 SUB_POL_ID
88368 2 POL_CODE
88368 4 SUB_POL_NAME
88368 5 CREATE_DATE
88368 6 SALE_SERVE_OPTION
88368 7 APPLY_TYPE_CODE
88368 3 SUB_POL_CODE
7 rows selected.
SQL> commit;
Commit complete.
select * from v$locked_object x , dba_objects m where x.OBJECT_ID=m.OBJECT_ID
select * from v$session where sid=3428
alter system kill session '3428,3249'--sid ,serial#
相关文章推荐
- Oracle数据库Date类型字段读写经验、查看Oracle字符集及修改字符集
- oracle中修改已有字段数据类型为clob的方法以及ssh框架中如何保存clob字段
- oracle 建表、最大ID、判断表是否已存在、字段的查询以及增删改、插入与修改语句
- oracle 修改 字段类型
- 修改oracle数据带有数据字段的数据字段的类型
- oracle修改字段类型时报"要更改的列必须为空"处理方法
- Oracle 修改带数据的字段类型
- 查看oracle的数据库连接数以及修改连接数
- Oracle 修改数据库字段的类型的语句
- oracle怎样修改表名、列名、字段类型、添加表列、删除表列
- oracle 修改某个字段的数据类型三种方式
- oracle 修改 字段类型
- Oracle 修改字段类型
- 如何修改oracle字段类型
- oracle 修改字段类型的方法
- oracle 修改字段类型的方法(转)
- Oracle 修改字段类型的方法
- Oracle 修改带数据的字段类型
- oracle修改字段名称和类型sql
- oracle查看编码以及修改编码