[oracle 11g 新特性] virtual column虚拟列
总结:虚拟列可以使用于一些特殊场合,实质是类似于函数列(即以 表中已有的列 经过函数运算得来),“虚拟列不存储在数据库中,是在执行查询时由oracle后台计算出来返回给用户”,因此虚拟列不会增加存储空间,但是由于需要计算,需要消耗额外的CPU Time。
---创建表时使用虚拟列
SQL> create table test4(id number,name varchar2(300),hash_id as(ora_hash(id)));
Table created
---alter 表新增虚拟列
SQL> create table test as select * from dba_objects;
Table created
SQL> alter table test add hash as (ora_hash(object_id));
Table altered
---below refer to https://oracleinstall.wordpress.com/2011/06/06/virtual-column-in-oracle-11g/
Virtual columns allows users to create columns whose data is not supplied by the user, but it is derived by oracle server implicitly from other columns. Most importantly, their disk space consumption is NULL because their data is not stored in the table.
Key points about Virtual columns:
1)Data can not be inserted into virtual column
2) The virtual column and the columns to be used in the derivation of virtual column data must belong to the same table.
3)It can be used as normal columns without any restriction. It can be constrained, indexed, and can be used in DML or DDL statements. Note that it cannot be updated in UPDATE statement
4)We can partition the table based on virtual column
We can use below query to define virtual columns defined in the users schema.
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, HIDDEN_COLUMN FROM USER_TAB_COLS WHERE VIRTUAL_COLUMN = ‘YES’;
5)we can not create virtual columns on Temporary tables, object types, clusters, External tables and Index Organized Tables
I tried to create table using following statment and used sysdate in the virtual column expression and got the following error.
Syntax
COLUMN [DATA TYPE] [GENERATED ALWAYS] AS (EXPRESSION) [VIRTUAL]
create table virtual_column (MEMBER_ID number(10), MEMBER_NAME varchar2(25), BIRTH_DATE date, AGE_IN_MONTHS number(5) AS(SYSDATE-BIRTH_DATE))
ORA-54002: only pure functions can be specified in a virtual column expression
create table virtual_column (MEMBER_ID number(10), MEMBER_NAME varchar2(25), MONTHLY_SALARY number(10,2), ANNUAL_SALARY number(10,2) AS(12*MONTHLY_SALARY))
SQL> insert into virtual_column values(1,’POOJITHA’,5000,10000); insert into ukatru.virtual_column values(1,’POOJITHA’,5000,10000) * ERROR at line 1: ORA-54013: INSERT operation disallowed on virtual columns
insert into virtual_column(MEMBER_ID,MEMBER_NAME,MONTHLY_SALARY) values(1,’POOJITHA’,5000);
SQL> select * from ukatru.virtual_column;
MEMBER_ID MEMBER_NAME MONTHLY_SALARY ANNUAL_SALARY ———- ————————- ————– ————- 1 POOJITHA 5000 60000
Create index on virtual columns:
CREATE INDEX IDX_ANUAL_SALARY ON virtual_column (ANNUAL_SALARY);
If you query user_indexes table the index is created as function based index.
SELECT INDEX_NAME, INDEX_TYPE, FUNCIDX_STATUS FROM USER_INDEXES WHERE TABLE_NAME = ‘VIRTUAL_COLUMN’;
INDEX_NAME INDEX_TYPE FUNCIDX_ —————————— ————————— ——– IDX_ANUAL_SALARY FUNCTION-BASED NORMAL ENABLED
we can use alter table command to add virtual column to the table.
alter table virtual_column add QUARTERLY_SALARY AS (MONTHLY_SALARY*3)
Adding constraint on the virtual column.
ALTER TABLE virtual_column ADD CONSTRAINT QUARTERLY_SALARY_CHECK CHECK(QUARTERLY_SALARY != 0);
SQL> insert into virtual_column(MEMBER_ID,MEMBER_NAME,MONTHLY_SALARY) values(2,’POOJITHA’,0); insert into virtual_column(MEMBER_ID,MEMBER_NAME,MONTHLY_SALARY) values(2,’POOJITHA’,0) * ERROR at line 1: ORA-02290: check constraint (QUARTERLY_SALARY_CHECK) violated
[oracle 11g 新特性] virtual column虚拟列的更多相关文章
- Oracle 11g 新特性 --SQL Plan Management 说明
Oracle 11g 新特性 --SQL Plan Management 说明 参见大神博主文章: http://blog.csdn.net/tianlesoftware/article/detail ...
- Oracle 11g 新特性 – HM(Hang Manager)简介
在这篇文章中我们会对oracle 11g 新特性—hang 管理器(Hang Manager) 进行介绍.我们需要说明,HM 只在RAC 数据库中存在. 在我们诊断数据库问题的时候,经常会遇到一些数据 ...
- Oracle 11g新特性
文章转自网络 Oracle 11g于2007年7月11日美国东部时间11时(北京时间11日22时)正式发布,11g是甲骨文公司30年来发布的最重要的数据库版本,根据用户的需求实现了信息生命周期管理(I ...
- 使用Oracle 11g新特性 Active Database Duplication 搭建Dataguard环境
Duplication Database 介绍 Duplicate database可以按照用途分为2种: duplicate database(复制出一个数据库) duplicate standby ...
- Oracle 11g 新特性(一)-- 虚拟列
数据库版本: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Oracle11g 增加了虚拟列的新特性, 具体说明如 ...
- Oracle 11g新特性虚拟列分区
如今有个需求:一个单据表要依照月份来分区.假设是在Oracle 10g上,仅仅能再加一个字段. 在Oracle 11g以后就不一样了.能够用虚拟列处理. SQL> select * from v ...
- Oracle 11g 新特性 -- 自适应游标共享(Adaptive Cursor Sharing: ACS) 说明(转载)
一.自适应游标共享(Adaptive Cursor Sharing) 说明 1.1 ACS概述绑定变量使Oracle DB 可以为多条SQL 语句共享单个游标,以减少分析SQL 语句所使用的共享内存量 ...
- Oracle 11g新特性延迟段创建和truncate的增强
下面测试Oracle 11g开始的新特性truncate的增强和延迟段空间创建. Oracle从11g开始,当用户创建一张空表的时候不会先分配段和空间,只有当对这张表插入第一行数据的时候才分配段和空间 ...
- Oracle 11g新特性 -- 延迟段
11gR2之前的版本中,当创建一张表时,会自动分配段空间,这样做有几个弊端: 1. 初始创建表时就需要分配空间,自然会占用一些时间,如果初始化多张表,这种影响就被放大. 2. 如果很多表开始的一段时间 ...
随机推荐
- Unity NGUI 图集Atlas制作
unity版本:4.5 NGUI版本:3.6.5 1.选择要制作的图片放到对应目录下,在Asset下新建一个文件夹Picture用于放置图片: 2.选中一张图片,打开Atlas Maker: 3.单击 ...
- html的两种提交按钮submit和button
转自:http://baiying.blog.51cto.com/1068039/1319784 html按钮有两种: <input type="button" value= ...
- linux下安装
挂载 1.虚拟机里选择ios文件2.挂载光驱命令: cd / mount /mnt/cdrom/ cd /mnt/cdrom/ ls 卸载 cd /umount /mnt/cdrom/ 安装 XXX. ...
- 【转】Kinect使用
文章转自http://blog.csdn.net/yangtrees/article/details/16106271 Kinect中深度值最大为4096mm (0x0fff) 微软建议在开发中使用1 ...
- Windows Azure 基本操作手册
http://www.cnblogs.com/sennly/p/4139663.html 基本测试信息 登陆地址:https://manage.windowsazure.cn(Azure管理门户,适用 ...
- HW2.22
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- 事件demo
delegate void MoveEventHandle(object source,MoveEventArgs e); public class MoveEventArgs:EventArgs { ...
- POJ1182食物链 (并查集)
第一反应就是和那个搞基的虫子的题很像(poj2492 http://www.cnblogs.com/wenruo/p/4658874.html),不过是把种类从2变成了3. 错在很白痴的地方,卡了好久 ...
- 问题.NET--win7 IIS唯一密钥属性“VALUE”设置为“DEFAULT.ASPX”时,无法添加类型为“add”的重复集合
问题现象:.NET--win7 IIS唯一密钥属性“VALUE”设置为“DEFAULT.ASPX”时,无法添加类型为“add”的重复集合 问题处理: 内容摘要: HTTP 错误 500.19 - ...
- Prime Land
http://poj.org/problem?id=1365 题意:给定一个数字n的拆分形式,然后让你求解n-1的值: 解析:直接爆搞 // File Name: poj1365.cpp // Aut ...