私はさまざまなデータの列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
列は "20161111
" のようなNULL
、space
、00000000
と文字列の日付で構成されています。
私は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の場合に含めないで除外するソリューションはありますか?
列のサンプルデータを表示できますか? –
写真を貼り付けたり、テキストを使用したりしないでください。 –
あなたは '20161111'を有効とみなしますか? (すなわち2016-11-11) –