Oracle uses SQL statements to modify field types

Source: Internet
Author: User

Oracle uses SQL statements to modify field types

1. If there is no data in the table

SQL code

123 altertable 表名 modify (字段名1 类型,字段名2 类型,字段名3 类型.....)  alter table student modify(id number(4));---将student表中id字段改为number,长度4   alter tablestudent modify(id number(4),studentName varchar2(100));

2. If there is data in the original table

SQL code

12 --修改原字段名  ALTERTABLE 表名 RENAME COLUMN 字段名 TO字段名1;

12345 --添加一个和原字段同名的字段  ALTERTABLE 表名 ADD 字段名 VARCHAR2(30);     --将原来的数据更新到新字段中,这是要注意,一定要显示进行数据类型转换(不同于MSSQL)  UPDATE 表名 SET 字段名 = CAST(字段名1 ASVARCHAR2(30));

12 --删除原来的备份字段  ALTERTABLE 表名 DROP COLUMN字段名1;

Oracle uses SQL statements to modify field types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.