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 9191749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:45:38+00:00 2026-06-17T20:45:38+00:00

I am working on following sql and keeping getting error on date part Error

  • 0

I am working on following sql and keeping getting error on date part

Error i am getting is :- ORA-01861: literal does not match format string

  SELECT COUNT(*) 
  FROM  STGDBA.INTERACTIONS
  WHERE APP_ID='Home Depot'
  AND PEGA_ID ='0'
  AND TO_CHAR(to_date(END_TIME))BETWEEN TO_DATE('2012-AUG-01', 'YYYY-MON-DD')AND TO_DATE
('2012-AUG-31', 'YYYY-MON-DD')

This is how date is stored in database:- 2011-10-24 08:46:31.621

  • 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-06-17T20:45:40+00:00Added an answer on June 17, 2026 at 8:45 pm

    First off, you should never store date or timestamp data in a table using a VARCHAR2 data type. You should always use the proper data type (date, timestamp, timestamp with time zone, etc.). Storing data in the wrong data type leads to performance problems (the optimizer’s cardinality estimates are generally going to be much less accurate and indexing the column becomes much more problematic) as well as bugs that are difficult to find when some application inadvertently stores a string with the wrong format in your table causing various queries to start throwing errors or when subtle changes in execution plans cause errors to suddenly start (or stop) appearing.

    Second, assuming every end_time string in every row in the table (whether or not the other two predicates are satisfied) is of the format YYYY-MM-DD HH24:MI:SS.FFF

    SELECT COUNT(*) 
      FROM  STGDBA.INTERACTIONS
      WHERE APP_ID='Home Depot'
      AND PEGA_ID ='0'
      AND to_date(substr(END_TIME,1,length(end_time)-4), 
                  'YYYY-MM-DD HH24:MI:SS' ) BETWEEN TO_DATE('2012-AUG-01', 'YYYY-MON-DD')
                                                AND TO_DATE('2012-AUG-31', 'YYYY-MON-DD')
    

    You always want to compare dates to dates and strings to strings so you don’t want to wrap the left side of the expression with a to_char. You always want to specify an explicit format mask when you call to_date, which is what I do here. And a date does not have subsecond precision so you have to strip off the fractional seconds (this would not be an issue if you declared end_time to be a timestamp(3)).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following SQL query isn't working. I think the error is on the first
I'm having difficulty working out how to 'error handle' as such the following SQL.
I am trying to execute the following SQL query but it is not working:
The following SQL statement is not working: SELECT stock.IdStock ,stock.Descr FROM [Inventory].[dbo].[Stock] stock WHERE
The following sql query is not working. select UserName from [User] where UserID Like
My following SQL is not working but when I use same regular expression in
I am working on my SQL, and I have the following statement: 1 SELECT
I'm working with a colleague and we're trying to reproduce the following SQL Query
I have the following SQL and it throws the error Ambiguous column name 'id'
I am working with the following SQL query: SELECT a.AppointmentId, a.Status, a.Type, a.Title, b.Days,

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.