我想調換使用查詢類似於下面的行列...甲骨文UNPIVOT和SYSDATE給人怪異的結果
WITH
query AS
(
SELECT SYSDATE AS SomeDate,
'One' AS One,
'Two' AS Two,
'Three' AS Three,
'Four' AS Four,
'Five' AS Five
FROM dual
),
up_query AS
(
SELECT *
FROM query
UNPIVOT
(
NUM FOR DUMMY
IN
(
One AS 'One',
Two AS 'Two',
Three AS 'Three',
Four AS 'Four',
Five AS 'Five'
)
)
)
SELECT SYSDATE, b.*
FROM up_query b;
我期待SomeDate以反映結果行SYSDATE ... 但這是我得到的結果:
SYSDATE SOMEDATE DUMMY NUM
09-DEC-11 09-DEC-07 One One
09-DEC-11 09-DEC-07 Two Two
09-DEC-11 09-DEC-07 Three Three
09-DEC-11 09-DEC-07 Four Four
09-DEC-11 09-DEC-07 Five Five
爲什麼SOMEDATE比SYSDATE早4年?
你也可以通過用'cast(SYSDATE as date)'替換'SYSDATE'來修復它。顯然SYSDATE是一種特殊的數據類型,並不總是一個DATE。看到這個詢問湯姆線程:http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:910228941137#47403557344816此外,你可以看到這個奇怪的類型轉換與此查詢:'選擇dump(sysdate),dump(cast(sysdate as date))from dual;' –