zoukankan      html  css  js  c++  java
  • Function Based Virtual Columns in Oracle 11 g Database

    Oracle Database 11g introduced new feature – virtual column. Instead storing data, the virtual column is calculated based on an expression stored in data dictionary. Let’s assume you have a table that stores customer information. The customer names are stored in two separate columns – first_name and last_name. The database queries often need to return the customer’s full name. Instead of storing the full name into the database or having to type it each time, you can define a new virtual column that is calculated, based on an expression: first_name || ' ' || last_name.

    Create a Oracle Database Table with calculated virtual column:

    CREATE TABLE customer(
       first_name VARCHAR2(32),
       last_name VARCHAR2(32),
       full_name AS (first_name || ' ' || last_name)
    );

    Add a new calculated virtual column to an existing Oracle Database Table:

    ALTER TABLE customer
              ADD full_name AS (first_name || ' ' || last_name)

    Some of the virtual column benefits include:

    • Automatic re-computation of derived columns for ad-hoc query tools.
    • Reduction in redundant disk space for columns that must be derived from other columns (e.g. a MONTH column that is derived from another DATE column).
    • Keep business logic in a single place.
    • Easier interval partitioning based on calculated columns.

    You should keep in mind that:

    • virtual columns may not reference other virtual columns;
    • virtual columns only within the containing table. You cannot reference columns within other tables.

    Oracle Database virtual columns has the nice side effect of assisting in streamlining partitioning. For example, assume that we have a table that is partitioned by year-month (i.e. 2007-07). With 11g virtual columns, instead of creating separate column, we can simply compute the partition key virtually, using a DATE column.

     

  • 相关阅读:
    洛谷 P2677 超级书架 2 题解
    洛谷 P3957 跳房子 二分+DP检验+单调队列优化
    BZOJ 1030 AC自动机+DP
    SPOJ-EPALIN 字符串哈希 回文
    URAL-1989 树状数组+字符串哈希
    POJ-2774 字符串哈希+二分
    CCF 201709-5 除法(线段树)
    CCF CSP个人题解汇总
    CCF CSP历年一二题代码汇总
    CCF 201803-4 棋局评估 (对抗搜索)
  • 原文地址:https://www.cnblogs.com/simonhaninmelbourne/p/2872441.html
Copyright © 2011-2022 走看看