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