You create a table with the PERIOD FOR clause to enable the use of the Temporal Validity feature of Oracle Database 12c.
Examine the table employees:
create table employees
(empno number, salary number,
deptid number, name varchar2(100),
period for employee_time);
Which three statements are true concerning the use of the ValidTime Temporal feature for the EMPLOYEES table?
A. The valid time columns are not populated by the Oracle Server automatically.
B. A SQL statment may filter on both transaction time and valid temporal time by using the AS OF TIMESTAP and PERIOD FOR clauses.
C. The employee_time_end value for the same row.
D. The valid time columns employee_time_start and employee_time_end are automatically created.
E. The valid time columns are visible by default when the table is described.
Correct Answer: ABD
E:错误。 时间列如果没有在period for 里面指定的话,会自动创建,但是是属于隐藏列。
C:错误。end 必须大于 start,否则会报 ORA-2290 错误。
在应用程序开发中,有时会碰到这样一个场景:设置一条记录的生效时间范围,比如某个产品信息,在某个时间段内是有效的,一般设计表时会在表中增加valid_start和valid_end这两个字段来限制,并通过设置这两个字段来实现具体产品的生效范围,如果查看当前生效的记录,则需要通过时间进行过滤。
Oracle 12.1.0.1引入了Temporal Validity(时间有效性),通过这一特性,在不增加列的情况下可以实现时间有效性的的判断,下面将对这一特性进行演示。
创建有valid-time维度的表
(1)显式指定两个date-time列
SQL> create table emp(empno number,salary number,deptid number,name varchar2(20),user_time_start date,user_time_end date,period for user_time (user_time_start,user_time_end));
(2)隐式的vaild-time列
SQL> create table emp2(empno number,salary number,deptid number,name varchar2(20), period for user_time);
vaild-time维度使用关键字"period for"指定。
如果使用隐式的valid-time列,不需要指两个日期列,oracle会创建两个隐藏列,并自动加上valid-time维度的前缀名。例如上一个例子中的前缀名是:user_time