我有列column_name VARCHAR2与各种数据。将其转换为DATE数据类型我写了下面的表达式:将Oracle VARCHAR2转换为DATE并排除无效数据
SELECT TO_DATE(column_name, 'YYYY/MM/DD') FROM schema.table;
但它给我的错误:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0 01841. 00000 - "(full) year must be between -4713 and +9999, and not be 0"
*Cause: Illegal year entered
*Action: Input year in the specified range
柱包括NULL,space,00000000和字符串日期,如 “20161111”。
要排除无效数据,我决定使用DECODE:
SELECT DECODE(column_name,
'', NULL,
'00000000', NULL,
TO_DATE(column_name, 'YYYY/MM/DD'))
FROM schema.table;
但在这种情况下,我得到了以下错误:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0 01841. 00000 - "(full) year must be between -4713 and +9999, and not be 0"
*Cause: Illegal year entered
*Action: Input year in the specified range
数据例如:
| # | column_name |
|---|-------------|
| 1 | 00000000 |
| 2 | |
| 3 | (null) |
| 4 | 20161111 |
什么时我做错了?
是否有解决方案排除所有无效的数据,而不包括在DECODE的情况下?
+0
你能显示一些来自列的示例数据吗? –
+1
请勿粘贴图片,请使用文字。 –
+0
你认为'20161111'有效吗? (即2016-11-11) –