Oracle database tables already have data, want to modify the type of a field, how to modify

Source: Internet
Author: User

One, ALTER TABLE name modify field type (word length);

If not, use the second method:

Two

--Create tablecreate table TABLE1 (  col1 Number (9),  col2 char (20));//attempt to modify ALTER TABLE TABLE1 MODIFY COL1 Number (10 ); --Modification succeeds because there is no data in the table//INSERT data INSERT INTO TABLE1 (COL1, COL2) VALUES (1, ' AAA ');//try again to modify alter TABLE TABLE1 MODIFY COL2 VARCHAR2 (20); --Modification failed because there is already data in the table, do not allow direct operation//cache tables CREATE TABLE T_table1 as SELECT * from table1;//delete the original table all data delete from table1;//modify field alter Table TABLE1 MODIFY COL1 number (9);--Modify success alter TABLE TABLE1 MODIFY COL2 VARCHAR2 (20);--Modify success//INSERT raw data inserts into TABLE1 Selec T * FROM t_table1;//Delete cache table drop table t_table1;//Note that if it is a char type, the number of bits is automatically padded with spaces, so use the char type with caution and trim () to verify that there are qualifying records. When the initial table structure, SELECT * from TABLE1 WHERE COL2 = ' aaa '; Is no data, requires SELECT * from TABLE1 WHERE TRIM (COL2) = ' AAA ';

Oracle database tables already have data, want to modify the type of a field, how to modify

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.