Oracle modifies the field type and length, and oracle modifies the field

Source: Internet
Author: User

Oracle modifies the field type and length, and oracle modifies the field

Modify the field name in Oracle

Alter table name rename column old field name to new field name

Modify the field type and length in Oracle

Alter table name modify Field Name Data Type

If you modify the data type from varchar2 to int and the field has a value, the following error is reported:


Reference solution: http://blog.csdn.net/itmyhome1990/article/details/8681206


Reprinted please indicate the source: http://blog.csdn.net/itmyhome1990/article/details/38869647



What is the operation for changing the field name in oracle?

Use the rename keyword to modify the field name: alter table name rename column old field name to new field name;
Use the modify keyword to modify the Data Type: alter table name modify Field name data type;

How can I change the field size of a table created in oracle?

Supplement the second floor
The field type is
If you want to change the value to a smaller value, you can directly use alter table table_name modify column datatype;
If there is any data, the data may be lost.
For example:
Table: stu (name varchar2 (20) should change the length of field name to 10
The table contains a piece of data: the length of name (the name is more than 10 in Huaxi Village, China), and data must be lost when captured.
Of course, if the data length in the table is less than 10, you can use the SQL statement segment to directly deal with it.
Begin
Alter table stu add (name2 varchar2 (10); add a new field
Update stu set name2 = substr (trim (name),); assign a value to the new field
Alter table stu drop (name); Delete the original field
Alter table stu rename column name2 to name; rename the new field
End;

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.