Oracle Action Columns

Source: Internet
Author: User

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

Related Article

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.