RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
oracle怎么修改字段 oracle怎么修改字段类型

oracle已经建好的表怎么修改字段大小?

只能改大。没有数据可能直接用 alter table table_name modify column datatype;

我们提供的服务有:成都网站制作、做网站、微信公众号开发、网站优化、网站认证、鼓楼ssl等。为1000多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的鼓楼网站制作公司

如果有数据,改小的话可以会丢失数据。

根据字段类型决定

alter table 表名 modify 字段名 varchar2(长度); 或

alter table 表名 modify 字段名 number(长度 );

比如:

表:stu(name varchar2(20)) 要将字段name的长度改为10

表中有一条数据:name(中国华西村刀光剑影) 长度超过10,截取的时候必然要丢失数据。

当然 如果表中的数据长度都小于10,则可以用sql语句段来直接搞定。

begin

alter table stu add (name2 varchar2(10));   增加新字段

update stu set name2=substr(trim(name),1,10);  赋值给新字段

alter table stu drop(name);                           删除原字段

alter table stu rename column name2 to name; 将新字段改名end;

oracle修改字段类型的方法

因为业务需要 修要修改某个字段数据类型有number( ) 变为number( )型

要是没有数据的话直接用以下语句即可

alter   table tb_test modify permile number( );

但是有数据的话 就不能用上面方法了

alter table tb_test add permile_temp number( )

update tb_test set permile_temp=permile;

alter table drop column permile;

alter table test rename column permile_temp to permile;

这种方法会使列名发生变化 而且字段顺序增加 有可能发生行迁移 对应用程序会产生影响

以下方法是比较好的方法

不用使列名发生变化 也不会发生表迁移 但这个有个缺点是表要更新两次

如果数据量较大的话 产生的undo和redo更多 前提也是要停机做

要是不停机的话 也可以采用在线重定义方式来做

以下是脚本:

alter table tb_test add permile_temp number;

Add/modify columns

alter table tb_test modify PERMILE null;

update tb_test set permile_temp=permile permile=null;

mit;

alter table tb_test modify permile number( );

update tb_test set permile=permile_temp permile_temp=null;

mit;

alter table tb_test drop column permile_temp;

alter table tb_test modify PERMILE not null;

lishixinzhi/Article/program/Oracle/201311/17913

oracle修改字段类型由varchar2修改为clob类型

发现clob类型比较特殊,和其他字段类型不同,不可以从其他字段类型直接转换为clob(blob也一样),可以通过long类型作为中间转换的桥梁,即先将varchar2转换为long,然后再将long转换为clob,即可。

SQL alter table test modify (loc long );

Table altered

SQL alter table test modify (loc clob );

Table altered

2、假设要修改字段有数据,则可以使用以下两种方法;

方法一:

alter table batchintfloadlog rename column resultinfo to resultinfo_temp;

alter table batchintfloadlog add resultinfo clob;

update batchintfloadlog set resultinfo=trim(resultinfo_temp);

alter table batchintfloadlog drop column resultinfo_temp;

方法二:

create table batchintfloadlog_temp  as select * from batchintfloadlog where 1=2; 

alter table batchintfloadlog_temp modify (resultinfo long); 

alter table batchintfloadlog_temp modify (resultinfo clob); 

insert into batchintfloadlog_temp select * from batchintfloadlog;

drop table batchintfloadlog; 

rename batchintfloadlog_temp to batchintfloadlog;

oracle中怎么更改表中字段名

首先方法是使用RENAME关键字:

修改字段名:alter table 表名 rename column 现列名 to 新列名;

修改表名:alter table 表名 rename to 新表名

增加字段语法:alter table tablename add (column datatype [default value][null/not null],….);

说明:alter table 表名 add (字段名 字段类型 默认值 是否为空);

例:alter table sf_users add (HeadPIC blob);

例:alter table sf_users add (userName varchar2(30) default '空' not null);

修改字段的语法:alter table tablename modify (column datatype [default value][null/not null],….);

说明:alter table 表名 modify (字段名 字段类型 默认值 是否为空);

例:alter table sf_InvoiceApply modify (BILLCODE number(4));

删除字段的语法:alter table tablename drop (column);

说明:alter table 表名 drop column 字段名;

例:alter table sf_users drop column HeadPIC;

字段的重命名:

说明:alter table 表名 rename  column  列名 to 新列名   (其中:column是关键字)

例:alter table sf_InvoiceApply rename column PIC to NEWPIC;

表的重命名:

说明:alter table 表名 rename to  新表名

例:alter table sf_InvoiceApply rename to  sf_New_InvoiceApply;

Oracle修改字段名、字段数据类型

语句:

alter table tableName rename column oldCName to newCName; -- 修改字段名

alter table tableName modify (cloumnName 数据类型); -- 修改数据类型

例如:

1、创建表:

CREATE TABLE Student(

id varchar2(32) primary key,

name varchar2(8) not null,

age number

);

2、修改字段名:

alter table Student rename column name to StuName;

3、修改数据类型:

alter table Student modify (id varchar2(64));

清醒时做事,糊涂时读书,大怒时睡觉,独处时思考;做一个幸福的人,读书,旅行,努力工作,关心身体和心情,成为最好的自己


分享标题:oracle怎么修改字段 oracle怎么修改字段类型
链接URL:http://cqwzjz.cn/article/hgsego.html