天天看點

【趣味問答 12C新特性】時間有效性(temporal validity)

編輯手記:oracle 12.2官方文檔已經釋出。相比很多朋友們都迫不及待要深入學習了。今天我們來測一測你對12c的新特性了解多少。

翻譯: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'); values ( 2,5.95, date'2016-06-01', null); 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:

  price_starttimestamp,   price_end  timestamp);

c:

  price_starttimestamp(0) with local time zone,   price_end  timestamp(0) with local time zone);

d:

  price_startnumber,   price_end  number);

e:

  price_end  timestamp with time zone);

簡單的一道題,希望你收獲的不止是答案。測試出一個結果很簡單,更重要的是知其是以然。歡迎大家踴躍參與,可以回複留言評論或者在大講堂讨論。本期答案将在明日晨讀揭曉。敬請關注。