Some ddl statements for Oracle operations

Source: Internet
Author: User
Recently, the program needs to generate DDL statements to modify the database table of the Oracle database. Therefore, I have summarized the situation of modifying the database table of the Oracle database as follows: 1. Add a column: ALTERTAB.

Recently, the program needs to generate DDL statements to modify the database table of the Oracle database. Therefore, I have summarized the situation of modifying the database table of the Oracle database as follows: 1. Add a column: ALTER TAB.

Recently, the program needs to generate DDL statements to modify the database table of the Oracle database. Therefore, I have summarized the situation of modifying the database table of the Oracle database as follows:

1. ADD a column: alter table table_name ADD (column_name VARCHAR2 (33, 2) DEFAULT '2' not null)

2. delete a COLUMN: alter table table_name drop column column_name

3. Modify the Data Type:

Data: ORA-01439: to change the data type, the column to be modified must be empty (empty)

No data: alter table table_name MODIFY (column_name NUMBER (222,2 ))

4. Modify the default value:

Consistent data types: alter table table_name MODIFY (column_name DEFAULT newVlaue)

Inconsistent Data Types: ORA-02262: ORA-932 appears when a type check is performed on the column default expression

5. Modify NULLABLE:

When changing NULL to not null:

Null: ORA-02296: Unable to enable (TABLE_NAME)-null found

NULL value does NOT exist: alter table table_name MODIFY (column_name not null)

When not null is changed to NULL: alter table table_name MODIFY (column_name NULL)

6. Modify the field name:

Name: alter table table_name rename column old_column_name TO new_column_name

Name does not match: ORA-00904: Invalid identifier

7. Modify the table name:

Name: alter table table_name rename to new_table_name;

Invalid name: ORA-00903: Invalid table name

8. Modify the field length:

When there is a length greater than the new value in the data: ORA-01441: the length of the Column cannot be reduced because some values are too large

Qualified: alter table table_name MODIFY (column_name VARCHAR2 (newLength ))

Note: Oracle imposes the following restrictions on table names and field names:

1. It must start with a letter

2. contains letters and numbers, and # $

3. cannot exceed 30 characters

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.