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

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


本文原始出处:http://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);



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


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值