阅读877 返回首页    go 阿里云 go 技术社区[云栖]


【趣味问答 12C新特性】时间有效性(temporal validity)

编辑手记:Oracle 12.2官方文档已经发布。相比很多朋友们都迫不及待要深入学习了。今天我们来测一测你对12C的新特性了解多少。


本文原始出处:https://www.plsqlchallenge.com/

翻译:newkid 苏旭辉


题目:

你正在创建一个产品报价的应用。它在如下的表保存这价格:

create table plch_product_prices (
  product_idint not null,
  unit_cost  number(10,2) not null);


你想要扩展它并保存价格修改的完整历史。你计划着使用12c的时间有效性功能(temporal validity)来完成。

哪些选项为这个表增加了时间有效期间,使得你过后执行这些语句的时候:

insert into plch_product_prices (
  product_id,unit_cost, price_start, price_end)

values (1,9.99, date'2000-01-01', null);


insert intoplch_product_prices (
  product_id,unit_cost, price_start, price_end

values (  2,5.50, date'2000-01-01', date'2016-06-01');


insert intoplch_product_prices (
  product_id,unit_cost, price_start, price_end

values ( 2,5.95, date'2016-06-01', null);


insert intoplch_product_prices (
  product_id,unit_cost, price_start, price_end)

values ( 3,7.00, date'2016-06-01', null);

select * fromplch_product_prices 
  as ofperiod for price date'2016-01-01';


最后的查询给出这个输出?


PRODUCT_ID   UNIT_COST   PRICE_START    PRICE_END
-------------------- -------------------- -------------------- ---------------
                     1                9.99       01-JAN-2000
                     2                5.5         01-JAN-2000   01-JUN-2016


注意,本题假设使用了如下的设置:

alter session set nls_date_format = 'dd-MON-yyyy';
alter session setnls_timestamp_format = 'dd-MON-yyyy';
alter session setnls_timestamp_tz_format = 'dd-MON-yyyy';
col price_start formata20
col price_endformat a20


选项如下:

A:

alter table plch_product_prices add (
  price_startdate,
  price_end  date);

alter tableplch_product_prices add period for price (
  price_start,price_end);


B:

alter table plch_product_prices add (
  price_starttimestamp,
  price_end  timestamp);

alter tableplch_product_prices add period for price (
  price_start,price_end);


C:

alter table plch_product_prices add (
  price_starttimestamp(0) with local time zone,
  price_end  timestamp(0) with local time zone);

alter tableplch_product_prices add period for price (
  price_start,price_end);


D:

alter table plch_product_prices add (
  price_startnumber,
  price_end  number);

alter tableplch_product_prices add period for price (
  price_start,price_end);


E:

alter table plch_product_prices add (
  price_startdate,
  price_end  timestamp with time zone);

alter tableplch_product_prices add period for price (
  price_start,price_end);



简单的一道题,希望你收获的不止是答案。测试出一个结果很简单,更重要的是知其所以然。欢迎大家踊跃参与,可以回复留言评论或者在大讲堂讨论。本期答案将在明日晨读揭晓。敬请关注。


文章转自数据和云公众号,原文链接

最后更新:2017-07-18 11:32:52

  上一篇:go  抬头看天,低头看路,五一看人:云时代的DBA,何去何从?
  下一篇:go  以12c Identity类型示范自我探索式学习方法