Oracle PL/SQL - Convert String to DATE

Introduction

You can use the TO_DATE function to convert string values into date values by using an appropriate format mask.

The masks are the same as in TO_CHAR:

v_date_dt := to_date(string variable[,format mask])

The DATE format allows you to store everything from centuries to seconds.

Demo

SQL>
SQL> declare-- from   www.j a v a2  s .c o m
  2      v_dt DATE;
  3      v_tx VARCHAR2(2000);
  4  begin
  5      v_dt := to_date('19:40','HH24:MI');
  6      v_tx := to_char(v_dt,'YYYY-MM-DD HH24:MI:SS');
  7      DBMS_OUTPUT.put_line(v_tx);
  8      v_dt := to_date('11-FEB-2006','DD-MON-YYYY'); --8
  9      v_tx := to_char(v_dt,'YYYY-MM-DD HH24:MI:SS');
 10      DBMS_OUTPUT.put_line(v_tx);
 11  end;
 12  /
2018-04-01 19:40:00
2006-02-11 00:00:00

PL/SQL procedure successfully completed.
SQL>

Related Topic