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
Ïà¹ØÎĵµ£º
ÒÔÏÂÁгöµÄÊÇOracle
Óû§¹ÜÀí¹ý³ÌÖг£ÓõÄһЩָÁÒÔ¹©´ó¼Ò²Î¿¼¡£
Oracle
Óû§¹ÜÀíÖ®Ò»¡¢´´½¨profile
Îļþ¡£
1.
SQL>Create
profile
ÎļþÃû limit
2.
  ......
Navicat for xxx ÊÇÒ»¸öÓÅÐãµÄÊý¾Ý¿â¹ÜÀí¿Í»§¶Ë£¬ÓÐ MySQL¡¢Oracle µÈ°æ±¾¡£½¨Òé´ó¼Ò×îºÃÓà Enterprise °æ±¾£¬¹¦ÄÜÈ«ÃæһЩ£¬µ«½ÏÖ®ÓÚÃâ·ÑµÄ Lite °æ£¬ÆóÒµ°æ¿ÉÊÇÒª»¨Òø×ÓÂòµÄ¡£
°²×° Navicat for Oracle ºó£¬Ê×ÏÈÐèÒª½¨Ò»¸ö“Á¬½Ó”£¬×÷Ϊij¸ö¹ÜÀíÈÎÎñµÄ±êʶ£¬ÒòΪ×÷Ϊ¿Í»§¶Ë£¬Ëü¿ÉÒ ......
½ñÌìÖØÐÂÕûÀíµçÄÔ£¬ÕÒµ½Ò»¸öÎļþ£¬¿´ÁËÏÂÈÕÆÚ£¨2006.11.3£© £¬Å²»Ð¡ÐÄÔÙ¶ªÁË£¬´æµ½ÍøÉÏÀ´É¹É¹¡£
SQL ÓïÑÔ·ÖÀࣺ
1 DDL£¨Êý¾Ý¶¨Òå £©ÓÃÓÚ´´½¨ºÍ¶¨ÒåÊý¾Ý¿â¶ÔÏ󣬲¢ÇÒ½«¶ÔÕâЩ¶ÔÏóµÄ¶¨Òå±£´æÔÚÊý¾Ý×ÖµäÖС£
creat table ´´½¨±í
alter table ÐÞ¸ ......
OracleÊý¾Ý¿âÊÇÒ»ÖÖ´óÐ͹ØϵÐ͵ÄÊý¾Ý¿â£¬ÎÒÃÇÖªµÀµ±Ê¹ÓÃÒ»¸öÊý¾Ý¿âʱ£¬½ö½öÄܹ»¿ØÖÆÄÄЩÈË¿ÉÒÔ·ÃÎÊÊý¾Ý¿â£¬ÄÄЩÈ˲»ÄÜ·ÃÎÊÊý¾Ý¿âÊÇÎÞ·¨Âú×ãÊý¾Ý¿â·ÃÎÊ¿ØÖƵġ£DBAÐèҪͨ¹ýÒ»ÖÖ»úÖÆÀ´ÏÞÖÆÓû§¿ÉÒÔ×öʲô£¬²»ÄÜ×öʲô£¬ÕâÔÚOracleÖпÉÒÔͨ¹ýΪÓû§ÉèÖÃȨÏÞÀ´ÊµÏÖ¡£È¨ÏÞ¾ÍÊÇÓû§¿ÉÒÔÖ´ÐÐijÖÖ²Ù×÷µÄȨÀû¡£¶ø½ÇÉ«ÊÇΪÁË·½±ãDBA¹Ü ......
create table emp2_log(
uname varchar2(20),
action varchar(10),
atime date
);
create or replace trigger trig
after insert or delete or update on emp2 for each row //°óÔÚÒ»ÕűíÉÏ,before after ¶¼¿É
ÒÔ,beforeÊÇ ²åÊý¾Ý֮ǰ£¬afterÊÇÖ®ºó
begin
&nb ......