I have a view where I am selecting a date column and reading it as a local date in denodo. In my column, I have a date '00-Jan-1900' like this which is giving issue so I wanted to replace this with empty. When I run this query, I get results as shown in the table2. But what I want is just an empty record in place of this date and looking like TABLE3.
Query:
select
to_localdate('dd-MM-yyyy', substring(replace("DATE", '00-Jan-1900', ''), 0, 10)) AS dtm
from XX
Table1:
DATE
22-Dec-2016
00-Jan-1900
30-Sep-2014
After replacing the date i get
Table2:
DATE
0201-12-22
0201-09-30
Is there a way i get output table like this?
TABLE3: DATE 22-Dec-2016
30-Sep-2014
In Oracle, you can use:
If you have the table:
Then, some extra hoops need to be jumped through to insert an invalid date (namely generating the date from binary data so that the normal validation process for date values can be skipped) by creating this function:
Then, you can have the data:
and:
Outputs:
To get rid of your invalid value, you can use:
Then:
Outputs:
db<>fiddle here
You can use:
And then just run your query and it should change the output (but you will need to make sure the format is set in future sessions when you run the query).
Or you can specify the format model using
TO_CHAR
: