Oracle 11g: Virtual Column

Oracle 11g has introduced a new feature that allows you to create a "virtual column",
an empty column that contains a function upon other table columns
(the function itself is stored in the data dictionary).

SQL> create table mytable (
  2   fname varchar2(25),
  3   lname varchar2(25)
  4  );

Table created
SQL> insert into mytable values('Nimish','Garg');

1 row inserted
SQL> alter table mytable add (fullname varchar2(60) generated always as (fname||' '||lname) virtual);

Table altered
SQL> select * from mytable ;

FNAME                      LNAME                      FULLNAME
------------------------- ------------------------- -------------------------
Nimish                         Garg                         Nimish Garg


Here is another example of this
--------------------------------------------------------------------------------
create table employee (
 empid number,
 ename varchar2(10),
 dname varchar2(10),
 salary number(9,2),
 comm number generated always as (round(salary*10/100),2) virtual
);




Related Posts:
- Oracle - DDL, DML and DCL commands
- ORA-01439: column to be modified must be empty to change datatype
- ORA-02438: Column check constraint cannot reference other columns
- Oracle: Delete duplicate rows from table


5 comments: