Virtual Columns in Oracle Database 11g
When queried, virtual columns appear to be normal table columns, but
their values are derived rather than being stored on disc. 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.
The script below creates and populates an employees table with two
levels of commission. It includes two virtual columns to display the
commission-based salary. The first uses the most abbreviated syntax
while the second uses the most verbose form.
CREATE TABLE employees (
id NUMBER,
first_name VARCHAR2(10),
last_name VARCHAR2(10),
salary NUMBER(9,2),
comm1 NUMBER(3),
comm2 NUMBER(3),
salary1 AS (ROUND(salary*(1+comm1/100),2)),
salary2 NUMBER GENERATED ALWAYS AS (ROUND(salary*(1+comm2/100),2)) VIRTUAL,
CONSTRAINT employees_pk PRIMARY KEY (id)
);
INSERT INTO employees (id, first_name, last_name, salary, comm1, comm2)
VALUES (1, 'JOHN', 'DOE', 100, 5, 10);
INSERT INTO employees (id, first_name, last_name, salary, comm1, comm2)
VALUES (2, 'JAYNE', 'DOE', 200, 10, 20);
COMMIT;
Querying the table shows the inserted data plus the derived commission-based salaries.
SELECT * from employees;
ID FIRST_NAME LAST_NAME SALARY COMM1 COMM2 SALARY1 SALARY2
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
1 JOHN DOE 100 5 10 105 110
2 JAYNE DOE 200 10 20 220 240
2 rows selected.
SQL>
The expression used to generate the virtual column is listed in the DATA_DEFAULT
column of the [DBA|ALL|USER]_TAB_COLUMNS
views.
COLUMN data_default FORMAT A50
SELECT column_name, data_default
from user_tab_columns
相关文档:
2009-04-22 22:00
来源:中国
IT
实验
室 作者:佚名
Oracle
客
户
端与服
务
器端的
连
接是通
过
客
户
端
发
出
连
接
请
求,由服
务
器端
监
听器
对
客
户
端
连
接
请
求
进
行合法
检查
,如果
连
接
请
求有效,
则进
行
连
接,否
则
拒
绝该连
接。 ......
oracle 存储过程和函数学习笔记
1、创建过程的语法:
Code
create [or replace] procedure procedure_name
[(argument[{in|out|in out}] type,
argument[{in|out|in out}] type)]&n ......
学习Oracle是一个漫长艰
辛的过程。如果没有兴趣,只是被迫学习,那么是很难学好的。学习到一定程度的时候,要想进一步提高,就不得不接触很多Oracle之外的东西,如
Unix,如网络、存储等。因此,要真的决心学好Oracle,就一定要有兴趣。有了兴趣,就会一切变得简单快乐起来。简单总结一下,那就是:兴趣、学
习、实践。 ......
1、查找表的所有索引(包括索引名,类型,构成列):
select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and t.table_name = i.table_name and t.table_name = 要查询的表
2、查找表的主键(包括名称,构成列):
select cu.* from user_cons_columns cu, user_con ......
在PL/SQL中使用阵列处理是一个很好的做法(如,使用bulk collect和forall)。批量处理能够大大减少PL/SQL语句执行引擎的环境切换次数,从而提高其性能。
另一个优秀示例是把存储过程中的所有代码放入锁定的软件包中,这样可以生成模块单元。把存储过程放入软件包里可以实现相关程序和功能的分组。当
单个包被使用 ......