First, modify the syntax of the field: ALTER TABLE tablename modify (field name type [default Value][null/not null],....);
There is a table named TB, field segment named Name, data type nchar (20).
1. ALTER TABLE TB Modify (name Nvarchar2 (20));
2, if the field has data, then to VARCHAR2 (40) execution will pop up: "ORA-01439: To change the data type, the column to be modified must be empty", the following method to solve the problem:
/* Modify the original field name name to name_tmp*/
ALTER TABLE TB Rename column name to Name_tmp;
/* Add a field with the same name as the original field name*/
ALTER TABLE TB Add name VARCHAR2 (40);
/* Update the original field NAME_TMP data to the added field name*/
Update TB set Name=trim (NAME_TMP);
/* Finish updating, delete the original field name_tmp*/
ALTER TABLE TB drop column name_tmp;
Summarize:
1, when the field has no data, or to modify the new type and the original type is compatible, you can directly modify modification.
2. When the field has data and is incompatible with the new type and the original type to be modified, create a new field to transfer indirectly.
Second, new fields
Syntax for new field: ALTER TABLE tablename Add (field name type [default Value][null/not null],....);
1. Add a field:
ALTER TABLE test1 Add (name VARCHAR2 () default ' anonymous ' not NULL);
2. Add three fields using one SQL statement at a time:
ALTER TABLE test1 Add (name VARCHAR2 () default ' anonymous ' NOT NULL,
The age integer default is not NULL, Has_money number (9,2));
Third, delete the field
Syntax for deleting a field: ALTER TABLE tablename drop column field name
Delete multiple fields: ALTER TABLE tablename drop (field name 1, field name 2)
Oracle field additions and deletions method summary