Thursday, November 21, 2013

Oracle 11g Virtual Columns

VIRTUAL COLUMNS

   With 11g release, Oracle allows user to explicitly create virtual columns in a table.  These virtual columns are associated with an expression, which always generate the value for the virtual column.
 

  •       The data type of the virtual column is also optional. If it is not explicitly specified, it attains the return data type of the expression.
  •         The virtual property of a column can be queried in VIRTUAL_COLUMN of USER_TAB_COLS table.
  •          INSERT and UPDATE operation are disallowed on virtual columns.

EXAMPLE :

SQL> create table orders(oid number,oname varchar2(12),qty as (oid*30));

SQL> insert into orders(oid,oname) values(1,'Mouse');

SQL> insert into orders(oid,oname) values(2,'Keyboard');

SQL> commit;

SQL> select * from orders;

SQL> select * from USER_TAB_COLS where TABLE_NAME='ORDERS'

SQL> desc orders;

No comments: