Solved

Need to know if string value has date format

Posted on 2011-03-15
4
461 Views
Last Modified: 2013-12-19
Hello,
I'm trying to know if a string value has date format. I use a function Is_Date to get that result, but no success.

select is_date('01/02/90xxx','DD/MM/YYYY HH24MISS') from dual;

Get error: ORA-01830: date format picture ends before converting entire input string


FUNCTION is_date (p_inDate DATE, p_format VARCHAR2)
      RETURN NUMBER
   AS
      v_dummy   DATE;
   BEGIN
      BEGIN

      SELECT TO_DATE (p_inDate, p_format) INTO v_dummy FROM DUAL;

      RETURN 1;
      EXCEPTION
         WHEN VALUE_ERROR
         THEN
            v_dummy := NULL;
      RETURN 0;
      END;

      RETURN v_dummy;
   END is_date;
0
Comment
Question by:miyahira
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 35139120
If the input parameter is a DATE, it must be valid.

Check out:
create or replace FUNCTION is_date (p_inDate varchar2, p_format VARCHAR2)
      RETURN NUMBER
   AS
      v_dummy   DATE;
   BEGIN
      BEGIN

      v_dummy := TO_DATE (p_inDate, p_format);

      RETURN 1;
      EXCEPTION
      when others then
            RETURN 0;
      END;
END is_date;
/

show errors



select is_date('01/02/90xxx','DD/MM/YYYY HH24MISS') from dual;
0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 250 total points
ID: 35139148
try something like this  ( I fixed some syntax errors too)


CREATE OR REPLACE FUNCTION is_date(p_indate VARCHAR2, p_format VARCHAR2)
    RETURN NUMBER
AS
    v_dummy   DATE;
BEGIN
    v_dummy  := TO_DATE(p_indate, p_format);

    RETURN 1;
EXCEPTION
    WHEN OTHERS
    THEN
        RETURN 0;
END is_date;
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 35139158
oops, too slow

same idea, but I removed the extra begin/end block which wasn't needed
0
 
LVL 1

Author Comment

by:miyahira
ID: 35139237
Thanks to both of you. I was blind, didn't see that I declared parameter p_indate as DATE and should be VARCHAR2
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question