Home > Database > Mysql Tutorial > oracle修改列的属性,给列重命名

oracle修改列的属性,给列重命名

WBOY
Release: 2016-06-07 15:30:43
Original
1583 people have browsed it

create table test1 (id varchar2(20) not null); alter table test1 add (name varchar2(30) default ‘无名氏’ not null); alter table test1 modify (name varchar2(16) default ‘unknown’); alter table test1 drop column name; 以上分别建立一个表

create table test1

(id varchar2(20) not null);

alter table test1
add (name varchar2(30) default ‘无名氏’ not null);

alter table test1
modify (name varchar2(16) default ‘unknown’);

alter table test1
drop column name;

以上分别建立一个表,增加,更改,删除一个列。其中需要注意的是如果某一列中已经存在值,如果你要修改的为比这些值还要窄的列宽这样将会出现一个错误。

例如前面如果我们插入一个值
insert into test1
values (’1′,’我们很爱你’);

然后曾修改列: alter table test1
modify (name varchar2(8));
将会得到以下错误:
ERROR 位于第 2 行:
ORA-01441: 无法减小列长度, 因为一些值过大

PS:改变已存在的表的列名

alter table table_name rename column col_old to col_new


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template