Difference between revisions of "Virtual Column"

From Ittichai Chammavanijakul's Wiki
Jump to navigation Jump to search
(Created page with "* Create a sample table with a VIRTUAL column. <pre> create table EMP_COMP ( empno NUMBER(4) not null, ename VARCHAR2(10), job VARCHAR2(9), mgr NU...")
 
Line 47: Line 47:
 
</pre>
 
</pre>
  
[[Categroy:Database_Features]]
+
[[Category:Database_Features]]
 
[[Category:Oracle_11g]]
 
[[Category:Oracle_11g]]

Revision as of 10:22, 10 March 2011

  • Create a sample table with a VIRTUAL column.
create table EMP_COMP
(
  empno      NUMBER(4) not null,
  ename      VARCHAR2(10),
  job        VARCHAR2(9),
  mgr        NUMBER(4),
  hiredate   DATE,
  salary     NUMBER(7,2),
  comm_pct   NUMBER(3,2),
  deptno     NUMBER(2),
  total_comp as (salary * (1 + comm_pct))
);

Table created

  • Virtual Column can be indexed
SQL> create index EMP_TCOMP_IDX on EMP_COMP(total_comp);
 
Index created 
  • Virtual Column can be used as partition key.
create table EMP_COMP
(
  empno      NUMBER(4) not null,
  ename      VARCHAR2(10),
  job        VARCHAR2(9),
  mgr        NUMBER(4),
  hiredate   DATE,
  salary     NUMBER(7,2),
  comm_pct   NUMBER(3,2),
  deptno     NUMBER(2),
  total_comp as (salary * (1 + comm_pct))
)
partition by range (total_comp)
(  partition p1 values less than (50000),
   partition p2 values less than (100000)
	 :
	 :
);