Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4601276
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:48:07+00:00 2026-05-21T23:48:07+00:00

I have the following query that I am attempting to use as a COMMAND

  • 0

I have the following query that I am attempting to use as a COMMAND in a crystal report that I am working on.

SELECT * FROM myTable
WHERE to_date(myTable.sdate, 'MM/dd/yyyy') <= {?EndDate}

This works fine, however my only concern is that the date may not always be in the correct format (due to user error). I know that when the to_date function fails it throws an exception.. is it possible to handle this exception in such a way that it ignores the corresponding row in my SELECT statement? Because otherwise my report would break if only one date in the entire database is incorrectly formatted.

I looked to see if Oracle offers an isDate function, but it seems like you are supposed to just handle the exception. Any help would be greatly appreciated. Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:48:08+00:00Added an answer on May 21, 2026 at 11:48 pm

    Echoing Tony’s comment, you’d be far better off storing dates in DATE columns rather than forcing a front-end query tool to find and handle these exceptions.

    If you’re stuck with an incorrect data model, however, the simplest option in earlier versions is to create a function that does the conversion and handles the error,

    CREATE OR REPLACE FUNCTION my_to_date( p_date_str IN VARCHAR2,
                                  p_format_mask IN VARCHAR2 )
      RETURN DATE
    IS
      l_date DATE;
    BEGIN
      l_date := to_date( p_date_str, p_format_mask );
      RETURN l_date;
    EXCEPTION
      WHEN others THEN
        RETURN null;
    END my_to_date;
    

    Your query would then become

    SELECT * 
      FROM myTable
     WHERE my_to_date(myTable.sdate, 'MM/dd/yyyy') <= {?EndDate}
    

    Of course, you’d most likely want a function-based index on the MY_TO_DATE call in order to make this query reasonably efficient.

    In 12.2, Oracle has added extensions to the to_date and cast functions to handle conversions that error

    SELECT * 
      FROM myTable
     WHERE to_date(myTable.sdate default null on conversion error, 'MM/dd/yyyy') <= {?EndDate}
    

    You could also use the validate_conversion function if you’re looking for all the rows that are (or are not) valid dates.

    SELECT *
      FROM myTable 
     WHERE validate_conversion( myTable.sdate as date, 'MM/DD/YYYY' ) = 1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say that we have the following query: SELECT DISTINCT COUNT(`users_id`) FROM `users_table`; this
I have following SQL query that selects some results from my table: select avg(c3),
I have the following query that retrieve the number of users per country; SELECT
Lets suppose that I have the following simple query var q = from p
I have table that I insert data with following query (from c# code): INSERT
I have a Premiums table that I attempting to query using the following LINQ-to-SQL:
I have the following query that looks for transactions that cancel themselves out from
I have the following query that works under Hibernate but not under eclipse: select
I have a query like the following: Select new mypackage.MyClass( u, max(sc.serviceDate)) from Unit
Let's say I have the following query: SELECT anInteger FROM table; How do I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.