One. The following describes the curd operation of the Oracle Database operations column
--Student Tables studentcreate table STUDENT ( ID number) not NULL, NAME VARCHAR2, NO VARCHAR2 (12), Age number (3));
Two. modifying table fields
--Add Student Table Class class field declare an_flag number DEFAULT 0; BEGIN SELECT COUNT (1) into an_flag from user_tab_columns WHERE table_name= ' STUDENT ' and Column_name= ' CLASS '; IF an_flag = 0 Then EXECUTE IMMEDIATE ' ALTER TABLE STUDENT ADD CLASS VARCHAR2 (+) '; EXECUTE IMMEDIATE ' COMMENT on COLUMN STUDENT. Class is ' student's classroom '; END IF; end;/
Three. Modifying the type of a table field
--Modify the type of the age field of the student table declare an_flag number DEFAULT 0; BEGIN SELECT COUNT (1) into an_flag from user_tab_columns WHERE table_name= ' STUDENT ' and column_ Name= ' age '; IF An_flag = 1 then EXECUTE IMMEDIATE ' ALTER TABLE STUDENT MODIFY Age CHAR (3) '; END IF; end;/
Four. Modify the name of the table field
--Modify the name of the age field of the student table declare an_flag number DEFAULT 0; BEGIN SELECT COUNT (1) into an_flag from user_tab_columns WHERE table_name= ' STUDENT ' and Column_name= ' age '; IF An_flag = 1 then EXECUTE IMMEDIATE ' ALTER TABLE STUDENT RENAME COLUMN age to age_to '; END IF; end;/
Five. Delete a table field
--Modify Student table Delete age field declare an_flag number DEFAULT 0; BEGIN SELECT COUNT (1) into an_flag from user_tab_columns WHERE table_name= ' STUDENT ' and column_ Name= ' age '; IF An_flag = 1 then EXECUTE IMMEDIATE ' ALTER TABLE STUDENT DROP COLUMN-age ';
Oracle Action Columns