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
Solved

Need to know if string value has date format

Posted on 2011-03-15
4
459 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

828 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