Friday, January 31, 2014

Using Virtual Column In a Table In Oracle Database.

Description: Virtual column are generally use for calculate data. Insert or Update operation are not allowed in virtual column. Virtual column are allowed in Oracle 11g Database.

CREATE TABLE EMPLOYEE_INFO
(EMPLOYEE_ID VARCHAR2(20),
 FIRST_NAME VARCHAR2(200),
 SALARY_DAILY NUMBER,
 DAY_IN_MONTH NUMBER,
 MONTHLY_SALARY NUMBER GENERATED ALWAYS AS  (SALARY_DAILY*DAY_IN_MONTH) VIRTUAL)

SQL>
SQL> Insert into EMPLOYEE_INFO
  2     (EMPLOYEE_ID, FIRST_NAME, SALARY_DAILY, DAY_IN_MONTH)
  3   Values
  4     ('120', 'RAJIB', 150, 30);

1 row created.

SQL> select * from EMPLOYEE_INFO;

EMPLOYEE_ID
--------------------
FIRST_NAME
----------------------------------------------------------------
SALARY_DAILY DAY_IN_MONTH MONTHLY_SALARY
------------ ------------ --------------
120
RAJIB
         150           30           4500

No comments:

Post a Comment