How To Use Virtual Column

Oracle Database 11g (11.1) and later versions can store expressions directly in base tables as Virtual columns, also known as Generated columns.When queried, virtual columns appear to be normal table columns, but their values are derived rather than being stored on disc.

  • They are defined by an expression. The result of evaluation of this expression becomes the value of the column.
  • The values of the virtual column are not stored in the database. Rather, it’s computed at run-time when you query the data.
  • You can’t update (in SET clause of update statement) the values of virtual column. These are read only values, that are computed dynamically and any attempt to modify them will result into oracle error.

The syntax for defining a virtual column is listed below.

column_name [datatype] [GENERATED ALWAYS] AS (expression) [VIRTUAL]

If the datatype is omitted, it is determined based on the result of the expression. The GENERATED ALWAYS and VIRTUAL keywords are provided for clarity only.

where the parameters within [] are optional and can be omitted. If you don’t mention the datatype, Oracle will decide it based on the result of the expression.

Excepting the above points, a virtual column, exists just like any other column of a normal table and the following points apply to it:

1.    Virtual columns can be used in the WHERE clause of UPDATE and DELETE statement but they can’t be modified by DML.

2.    Statistics can be collected on them.

3.    They can be used as a partition key in virtual column based partitioning.

4.    Indexes can be created on them. As you might have guessed, oracle

5.    would create function based indexes as we create on normal tables.

6.    Constraints can be created on them.

SQL> CREATE TABLE orders
  2      ( order_id           NUMBER(12),
  3        order_date         TIMESTAMP WITH LOCAL TIME ZONE,
  4        order_mode         VARCHAR2(8),
  5        customer_id        NUMBER(6),
  6        order_status       NUMBER(2),
  7        order_total        NUMBER(8,2),
  8        sales_rep_id       NUMBER(6),
  9        promotion_id       NUMBER(6),
 10        CONSTRAINT orders_pk PRIMARY KEY(order_id)
 11      )
 12    PARTITION BY RANGE(order_date)
 13      ( PARTITION Q1_2005 VALUES LESS THAN (TO_DATE('01-APR-2005','DD-MON-YYYY')),
 14        PARTITION Q2_2005 VALUES LESS THAN (TO_DATE('01-JUL-2005','DD-MON-YYYY')),
 15        PARTITION Q3_2005 VALUES LESS THAN (TO_DATE('01-OCT-2005','DD-MON-YYYY')),
 16        PARTITION Q4_2005 VALUES LESS THAN (TO_DATE('01-JAN-2006','DD-MON-YYYY'))
 17      );
    ( PARTITION Q1_2005 VALUES LESS THAN (TO_DATE('01-APR-2005','DD-MON-YYYY')),
                                          *
ERROR at line 13:
ORA-30078: partition bound must be TIME/TIMESTAMP WITH TIME ZONE literals
SQL> CREATE TABLE orders_vcol

  2      ( order_id           NUMBER(12),

  3        order_date         TIMESTAMP(6) WITH LOCAL TIME ZONE,

  4        order_mode         VARCHAR2(8),

  5        customer_id        NUMBER(6),

  6        order_status       NUMBER(2),

  7        order_total        NUMBER(8,2),

  8        sales_rep_id       NUMBER(6),

  9        promotion_id       NUMBER(6),

 10        vcol_gmt TIMESTAMP(6) AS (SYS_EXTRACT_UTC(order_date))

 11        virtual,

 12        CONSTRAINT orders_vpk PRIMARY KEY(order_id)

 13      )

 14  /

 

Table created.

SQL> col DATA_TYPE for a30

SQL> col DATA_DEFAULT for a30

SQL> SELECT column_name, data_type, data_length, data_default, virtual_column

  2  FROM user_tab_cols

  3  WHERE table_name = 'ORDERS_VCOL';

 

COLUMN_NAME                    DATA_TYPE                                                         DATA_LENGTH DATA_DEFAULT                   VIR

------------------------------ ------------------------------                                  ----------- ------------------------------         ---

ORDER_ID                           NUMBER                                                                 22                                NO

ORDER_DATE                     TIMESTAMP(6) WITH LOCAL TIME ZONE                11                                NO

ORDER_MODE                     VARCHAR2                                                              8                                NO

CUSTOMER_ID                    NUMBER                                                                  22                                NO

ORDER_STATUS                   NUMBER                                                                 22                                NO

ORDER_TOTAL                    NUMBER                                                                  22                                NO

SALES_REP_ID                   NUMBER                                                                    22                                NO

PROMOTION_ID                   NUMBER                                                                22                                NO

VCOL_GMT                       TIMESTAMP(6)                            11 SYS_EXTRACT_UTC("ORDER_DATE")  YES

9 rows selected.

Limitations on Virtual Columns

1.    A virtual column can only be of scalar datatype or XMLDATATYE. It can’t be a user defined type, LOB or RAW.

2.    All columns mentioned as part of the virtual column expression should belong to the same table.

3.    No DMLs are allowed on the virtual columns.

4.    The virtual column expression can’t reference any other virtual column.

5.    Virtual columns can only be created on ordinary tables. They can’t

6.    be created on index-organized, external, object, cluster or temporary

7.    tables.

8.    If a deterministic function is used as virtual column expression,

9.    that virtual column can’t be used as a partitioning key for virtual

10. column-based partitioning.

Notes and restrictions on virtual columns include:

·         Indexes defined against virtual columns are equivalent to function-based indexes.

·         Virtual columns can be referenced in the WHERE clause of updates and deletes, but they cannot be manipulated by DML.

·         Tables containing virtual columns can still be eligible for result caching.

·         Functions in expressions must be deterministic at the time of

·         table creation, but can subsequently be recompiled and made

·         non-deterministic without invalidating the virtual column. In such cases

·          the following steps must be taken after the function is recompiled:

o    Constraint on the virtual column must be disabled and re-enabled.

o    Indexes on the virtual column must be rebuilt.

o    Materialized views that access the virtual column must be fully refreshed.

o    The result cache must be flushed if cached queries have accessed the virtual column.

o    Table statistics must be regathered.

·         Virtual columns are not supported for index-organized, external, object, cluster, or temporary tables.

·         The expression used in the virtual column definition has the following restrictions:

o    It cannot refer to another virtual column by name.

o    It can only refer to columns defined in the same table.

o    If it refers to a deterministic user-defined function, it cannot be used as a partitioning key column.

o    The output of the expression must be a scalar value. It

o    cannot return an Oracle supplied datatype, a user-defined type, or LOB

o    or LONG RAW.

References:

1 Oracle Documentation
2 http://viralpatel.net/blogs/oracle-11g-new-feature-virtual-column/

 


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13750068/viewspace-2144136/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/13750068/viewspace-2144136/

Snowflake数据共享实战:零拷贝、安全视图与四种模式深度解析 数据共享是现代数据架构的核心能力,其本质是在保障数据主权前提下实现跨主体、低延迟、高安全的协同使用。Snowflake通过存储与计算分离架构,实现了真正的零拷贝共享——数据不动、元数据指针驱动、权限毫秒生效。关键技术支撑包括Secure View(强制逻辑隔离、阻断谓词下推)、行级/列级策略(RLS+Masking)及分离式账单模型。该能力广泛应用于集团内多BU数据打通、SaaS厂商API对接、合规审计型数据分发等场景。本文聚焦Snowflake数据共享的工程落地,覆盖Direct Share、Data E 阅读详情

相关推荐

构建可审计的RAG系统:检索噪声、上下文饱和与答案漂移的实战应对

RAG(检索增强生成)是一种将外部知识库与大语言模型结合的关键技术,其核心原理在于通过向量检索获取相关上下文,再交由LLM进行条件化生成。技术价值体现在避免幻觉、提升事实准确性与支持私有数据闭环,广泛应用于法律文档审查、临床试验分析、内部知识库和多语言技术文档搜索等高可靠性场景。然而真实落地中,三大典型问题持续制约效果:检索噪声导致无关信息干扰、上下文窗口饱和引发静默截断、答案漂移造成结果不一致。本文聚焦LlamaIndex+Gemini Flash+Mirascope技术栈,深入剖析这三类失效模式的根因与

chuange6363的博客 615

Replicat Abended With Error OGG-01169 Encountered an update where all key columns for target table

Replicat Abended With Error OGG-01169 Encountered an update where all key columns for target table are not present, INFO OGG-01451 Unique key cannot be used due to the inclusion of virtual columns (Doc ID 1578985.1)

gsforget321的博客 1340

MySQL表生成列(Generated Columns)的使用说明

原文地址 MySQL的表生成列通常又叫做虚拟列或计算列。这个生成列的值是在列定义时包含了一个计算表达式计算得到的,有两种类型的生成列: Virtual(虚拟):这个类型的列会在读取表记录时自动计算此列的结果并返回。 Stored(存储):这个类型的列会在表中插入一条数据时自动计算对应的值,并插入到这个列中,那么这个列会作为一个常规列存在表中。 虚拟生成列有时候比存储生成列更有用,因为它不会占...

zxstrive的专栏 5151

Navicat 11执行SQL语句报错

Navicat 11执行SQL语句报错 [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sq

weixin_39561762的博客 1484

NUMA;numactl;的一些总结

依赖架构是否支持NUMA的平衡:ARCH_SUPPORTS_NUMA_BALANCING,同时!是否打开基于NUMA内存平衡的自动页错误中断。内存会被映射到相应的本地内存节点上。在NUMA机器上,如果一个CPU访问远端节点,性能损耗非常大。如果打开这个内存平衡功能,内核会周期性采样线程的内存访问,对内存的申请做干涉,尽量将内存申请放到本地内存节点(通过页错误重新做内存申请)。默认打开NUMA 平衡功能。依赖于NUMA_BALANCING。

mzhan017的博客 1002

Redis 可视化工具 RedisInsight 的保姆级安装以及使用(最新)

Redis 可视化工具 RedisInsight 的保姆级安装以及使用(最新)

一名全栈小白的博客 1万+

【OGG】OGG故障错误处理总结

【OGG】OGG故障错误处理总结 第一章GoldenGate错误分析与处理 在维护GoldenGate过程中,由于各种意外情况,难免还...

小麦苗DBA宝典 9499

LQR控制算法调参指南:如何通过Bryson‘s Rule和Trial-and-Error优化自动驾驶性能?

本文深入探讨了LQR控制算法在自动驾驶系统中的调参策略,从Bryson's Rule的基础应用到工程落地的优化方法。通过动态权重适应、非对角项引入和多目标权衡等技巧,提升车辆轨迹跟踪精度与操控舒适性。文章还介绍了数据驱动的调参流程和典型问题的解决方案,为自动驾驶工程师提供实用指南。

kkk56的博客 1026

How To Use Virtual Column-Based Partitioning

上一篇我介绍和测试了oracle 11g版本引入的虚拟列新特性,本文继续测试分区键基于表的虚拟列: Prior releases of Oracle only allowed a table to be parti...

164

同花顺Supermind量化交易 技术面分析专题(一)-- 相似k线的形态验证与选股

W底”,“多头上涨”,“趋势回踩”,”上涨中继“这些都是常见的K线形态,以”上涨中继“为例,当股价快速上涨后,出现盘整形态而非顶部形态,预示股价还会进一步上涨,那么本节主要讲述”上涨中继”形态是否能够预测未来股价上涨,以及如何应用“上涨中继”形态,来快速选股。"相似K线"技术相比于传统的K线组合而言更具技术性,其还有较多的运用空间,比如:运用顶部形态来监控个股潜在的下跌风险,运用相似度来监控个股是否脱离大盘走势,研究各类形态的上涨预测能力,并应用于选股等等。第一步:选取一段标准的“上涨中继”形态K线图。

qq_22808537的博客 4553

Shell数学计算(算术运算,加减乘除运算)

声明: 本篇博客的学习途径主要为以下网站和课堂讲解,发博客目的仅为学习使用,在该博客的基础上做了一定程序的简略和修改。 参考博客 : 原文链接:http://c.biancheng.net/shell/ Shell数学计算Shell数学计算数学计算命令对整数进行数学运算: (()) / let / $[] /exprShell (())Shell let命令bc命令:一款数学计算器在 Shell 中使用 bc 计算器 Shell数学计算 默认情况下,Shell 不会直接进行算术运算,而是把+两边的数据(数

AKUANer的博客 2万+

MySQL generated column

MySQL 5.7之后增加了对generated column的支持,能够在此列中指定一些预先定义的表达式(predefined expression)或者是结合其他列使用一些函数计算出相应的结果做给该列的值语法 column_name data_type [GENERATED ALWAYS] AS (expression) [VIRTUAL | STORED] [UNIQUE [KEY]] g

qiuqurenkong的博客 2663

物联网通信中NB-IoT、Cat.1、LTE-M该如何选择?

首先我们要确定我们产品的关键需求,例如:我们的设备是否对数据传输速率有较高的要求,有较高要求我们就需要选择较高传输速率的Cat.1来开发我们的产品。同时关于产品性能方面,我们对功耗、延迟、可靠性也会有所要求,例如我们的产品为移动端产品,不方便布线以及安装电源,那我们就会采用电池供电的方式,所以在选择时可以优先考虑低功耗产品,最终结合其他需求选择出合适的协议。首先,我们需求的产品是不同的,我们需要根据产品需求或项目需求来进行选择,NB-IoT、Cat.1、Cat.M都有属于自己的优势。

a1809032425的博客 1216

Oracle Database 12c Security - 7. Controlled Data Access with Virtual Private Database

Virtual Private Database (VPD) INTRODUCTION TO VIRTUAL PRIVATE DATABASE VPD使用Row-Level Security (RLS) package DBMS_RLS实现。 VPD的范围是当前数据库。 How VPD Works 通过创建VPD policy,VPD支持DML和SELECT,不支持DDL。 VPD返回VARCHAR2 predicate,并附着在where条件中。这样用户只能看到自己相关的数据。 VPD policy只能用

In-Memory Computing Technology 612

js逆向实战:爬取淘宝男装商品

本文介绍了一个淘宝商品数据爬取程序的技术实现方案。该程序通过分析淘宝H5页面接口,实现了商品名称、价格、销量等关键信息的抓取,并支持图片下载功能。核心内容包括:1. 使用Request库发送HTTP请求获取数据;2. 通过逆向分析淘宝的签名算法(MD5加密)生成合法请求;3. 解析JSON数据并提取商品信息;4. 处理分页参数实现多页数据爬取;5. 将数据保存为CSV文件并下载商品图片。程序还实现了反爬虫绕过、错误处理、文件管理等辅助功能,完整展示了从数据采集到存储的全过程。

那些看似不起波澜的日复一日,会在某天让你看到坚持的意义 1574

黑猫带你学Nand第8篇:NandFlash的供电情况详解

是指在任何工作条件下,设备允许的最大电压、电流、功率以及温度等参数的界限值。

黑猫奥利奥的博客 1150

MySQL子查询作为列,子查询作为MySQL中的生成列?

Can I create a generated column in table A which sums up a column in table B with a tableA_id of the row in table A?Suppose I have a table of of families, and a table of children. I want a sum of the...

weixin_33235712的博客 392

【DevOps】rancher集成ldap,实现统一账号登录

登录到rancher控制台,选择【安全】-【认证】 选择【OpenLDAP】 其中【搜索起点】需要去ldap界面查配置完成

CN_Eden 1094

学习之旅5-mysql补充

1、mysql查询 关于左右连接 :结果集小的表驱动大表,减少循环次数,达到优化目的,但是需要结合索引进一步优化 union all 与 union 的区别:前者不去重,后者自动去重 show 语句: show databases; 查询所有库 show tables; 查询所有表 show tables from city; 查询city库中所有表 show processlist; 查询mysql连接情况 show full processlist; 查询mysql连接的详细情况 show c

Mrzhengdan的博客 189

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Ceres 数值求导原理与使用

本文介绍了数值求导方法及其在Ceres Solver中的应用。主要内容包括: 数值求导方法: 前向差分法(Forward Differences):误差O(h),计算简单但精度较低 中心差分法(Central Differences):误差O(h²),精度更高但计算量加倍 Ridders方法:通过Richardson外推法获得更高精度,误差下降更快但计算成本最高 在Ceres中的实现: 使用NumericDiffCostFunction模板类 通过改变模板参数选择不同差分方法 提供具体实现示例和性能对比 使

人无远虑,必有近忧 900

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

SQL Server Latch Classes Library

https://www.sqlskills.com/help/latches/ (Companion SQL Server Wait Types Library) This site lists all latch classes in SQL Server 2005 onward and gives detailed information about where they occur insi...

weixin_33709590的博客 367

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

What is information_schema used in mysql

What is information_schema used in mysql

在路上 306

signature=073e9d8cfe69aa5953d35da3e9e56b44,sequelize/changelog.md at b49f936e9aa316cf4a13bade76585ac...

4.0.0 (final)[ADDED] Add isSoftDeleted helper method to model instance #7408[FIXED] Map isolation level strings to tedious isolation level [MSSQL] #7296[ADDED] addConstraint, removeConstraint, showCon...

weixin_30619981的博客 1319

CPU 缓存 | 原理、映射、一致性

……

u013669912的博客 413

Debugging Embedded Linux

Section #6. Debugging Embedded Linux From a device driver perspective, embedded software developers often face interfaces not commonly found on conventional computers. Figure 1.3 shows a hypothetical...

mounter625的专栏 1164
上一篇: How To Using Flashback Data Archive (Oracle Total Recall)
下一篇: How To Use Virtual Column-Based Partitioning
cppg67031
博客等级 码龄12年 2粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值