Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

convert varchar2 to date type

I have a create_date field of type varchar2(). There are invalid values ​​like this:

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I exclude them so that I can insert them from this table into another table in a field with a date value?
I need correctly entered dates like 10/02/2022, 08/05/2021, etc.

>Solution :

You may use validate_conversion function to filter rows that contain invalid string representation of a date:

with a(dt) as (
  select *
  from sys.odcivarchar2list(
  '21.10.2022',
  '31.02.2022',
  'Не дата',
  '01.12.2021',
  '00.10.2021',
  '   '
  )
)
select
  dt as char_value,
  to_date(dt, 'dd.mm.yyyy') as date_value
from a
where validate_conversion(dt as date, 'dd.mm.yyyy') = 1
CHAR_VALUE DATE_VALUE
21.10.2022 2022-10-21 00:00:00
01.12.2021 2021-12-01 00:00:00

fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading