oracle 11g中的虛擬列

2021-08-31 05:55:53 字數 1901 閱讀 8975

在oracle 11g中,支援虛擬列,注意虛擬列是可以根據其他列動態計算出來的,

語法:column_name [datatype] [generated always] as [expression] [virtual]

例子:create table employee (

empl_id number,

empl_nm varchar2(50),

monthly_sal number(10,2),

bonus number(10,2),

total_sal number(10,2) generated always as (monthly_sal*12 + bonus) );

再看下資料字典:

select column_name, data_type, data_length, data_default, virtual_column from user_tab_cols where table_name = 'employee'; column_name | data_type | data_length | data_default | virtual_column empl_id | number | 22 | null | noempl_nm | varchar2 | 50 | null | nomonthly_sal | number | 22 | null | nobonus | number | 22 | null | nototal_sal | number | 22 | "monthly_sal"*12+"bonus" | yes

可以對錶進行的列進行增加:

drop table employee purge;

create table employee (empl_id number, empl_nm varchar2(50), monthly_sal number(10,2), bonus number(10,2) ); alter table employee add (total_sal as (monthly_sal * 12 + bonus));

可以對錶的其他列進行增加,但不能對虛擬列進行增加和修改:

insert into employee (empl_id, empl_nm, monthly_sal, bonus)

with data as

(select 100 empl_id, 'aaa' empl_nm, 20000 monthly_sal, 3000 bonus from dual union select 200, 'bbb', 12000, 2000 from dual union select 300, 'ccc', 32100, 1000 from dual union select 400, 'ddd', 24300, 5000 from dual union select 500, 'eee', 12300, 8000 from dual) select * from data;

--可以為虛擬列建立索引,索引型別為函式索引

create index idx_total_sal on employee(total_sal); select index_name, index_type from user_indexes where table_name = 'employee'; index_name index_type idx_total_sal function-based normal

虛擬列還可以作為分割槽表的分割槽鍵

比如:create table test_part(i1 int, i2 as (i1+100))

partition by range(i2)

(partition part1 values less than(100),

partition part2 values less than(200),

partition part3 values less than(maxvalue));

Oracle 11g 新特性(一) 虛擬列

資料庫版本 oracle database 11g enterprise edition release 11.2.0.2.0 64bit oracle11g 增加了虛擬列的新特性,具體說明如下 1 只能在堆組織表 普通表 上建立虛擬列,不能在索引組織表 外部表 臨時表上建立虛擬列 2 虛擬列不能是...

解除安裝oracle 11g

估計和以前的版本一樣,先刪除物理檔案,然後再刪除登錄檔的檔案。大致方法如下 1 刪除物理檔案 1 oracle安裝檔案。2 系統目錄下,program files檔案下的oracle檔案 2 登錄檔中大概有這麼幾個地方 hkey local machine software 刪除oracle目錄 h...

oracle 11G 解除安裝

oracle deinstall deconfig tool start check operation start 安裝檢查配置開始 選擇進行解除安裝的 oracle 主目錄型別為 sidb 檢查主產品清單位置是否存在 c program files oracle inventory 安裝檢查配置...