Monday 2 July 2012

How to get only valid dates from a varchar date field in oracle





First we need to create a function as below:


CREATE OR REPLACE FUNCTION MY2DATE (p_str IN VARCHAR2
  ,format_picture IN VARCHAR2
)
   RETURN DATE
IS
BEGIN
   RETURN TO_DATE(p_str, format_picture);
EXCEPTION
   WHEN OTHERS
   THEN
      RETURN NULL;
END;




Call that function with field name and the valid date format while selecting:

SELECT MY2DATE(FIRST,'dd/mm/YYYY HH:MM AM') FROM ORDERS

No comments:

Post a Comment