2017-04-19 158 views

回答

1

我覺得這裏是一個原因,這不會導致一個錯誤:

to_timestamp and to_date exist to handle input formats that cannot be converted by simple casting. These functions interpret input liberally, with minimal error checking. While they produce valid output, the conversion can yield unexpected results. For example, input to these functions is not restricted by normal ranges, thus to_date('20096040','YYYYMMDD') returns 2014-01-17 rather than causing an error. Casting does not have this behavior.

https://www.postgresql.org/docs/9.6/static/functions-formatting.html

+0

確定..感謝您的回答..但我真的一個當日期是錯誤的月份> 12爲它返回一個錯誤示例和日期> 32 ..我該怎麼做,或者我可以使用什麼 – Kamfasage

+0

@Kamfasage - 如果您嘗試投射'選擇投射('20172202'作爲日期)',您將收到錯誤 –

+0

,所以我應該這樣做: 'select to_date(cast('20172202'as date),YYYYMMDD); ' 這不起作用,因爲** to_date **函數具有參數文本和文本 – Kamfasage

0

我有什麼,我想/ 我使用的TO_CHAR,而不是TO_DATE答案我把fisrt參數轉換成日期..

select to_char(DATE '20162202,'YYYYMMDD') into datResult ; 

所以我現在可以有一個錯誤..

感謝您的幫助大家