閱讀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類型示範自我探索式學習方法