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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:04:05+00:00 2026-05-24T17:04:05+00:00

We have a query that includes (but has other joins, tables and where conditions):

  • 0

We have a query that includes (but has other joins, tables and where conditions):

SELECT
    o.contact_id, 
    o.completed_date, 
    o.submitted_date
FROM
    orders o /* 860,000 row table */
WHERE   
    ? <= o.submitted_date
    AND o.submitted_date < ? + 1

called from a Java application.

The ? paramaters allow checking for orders submitted between two dates.

However, this query runs very slowly.

We converted to run from PL/SQL for testing as follows:

SubmittedDateFrom date:=to_date('2011-07-15', 'yyyy-mm-dd');
SubmittedDateTo date:=to_date('2011-07-15', 'yyyy-mm-dd');
CURSOR c_orgs    IS    
SELECT
    o.contact_id, 
    o.completed_date, 
    o.submitted_date
FROM
    orders o
WHERE   
    SubmittedDateFrom <= o.submitted_date
    AND o.submitted_date < SubmittedDateTo + 1;
BEGIN
    FOR c_o IN c_orgs LOOP
        DBMS_OUTPUT.put_line('Submitted date = '||c_o.submitted_date);                               
    END LOOP;
END;

IF we either:

  1. convert the SubmittedDateTo value to to_date('2011-07-16', 'yyyy-mm-dd') (i.e. do the arithmetic outside the query),
  2. make SubmittedDateTo a string and use “to_date('SubmittedDateTo', 'yyyy-mm-dd') + 1″ as the second condition in the WHERE.

THEN, the query speeds up dramatically ( < 1 second vs. 44+ seconds).

Further information:

  • running an explain plan on the query gives the error ORA-00932: inconsistent datatypes: expected DATE got NUMBER
  • the submitted_date column has an index and stats, etc. have been run
  • wrapping the SubmittedDateTo + 1 in a trunc() call does not affect performance
  • We do not have a non-9i database with similar data volumes, etc. to test if it’s the version of Oracle or not.

The question is: we are unable to find any information which clearly states that the Oracle 9i Optimizer has an issue with this kind of date arithmetic. Is that what’s happening here or is there something else going on?

  • 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-24T17:04:05+00:00Added an answer on May 24, 2026 at 5:04 pm

    I’d always ensure that all conversions are handled explicitly (and assuming o.submitted_date is a DATE datatype):

    DECLARE
      CURSOR c_orgs    
      IS
         SELECT o.contact_id,      
                o.completed_date,
                o.submitted_date 
           FROM orders o 
          WHERE o.submitted_date BETWEEN TO_DATE(SubmittedDateFrom, 'yyyy-mm-dd') 
                                     AND TO_DATE(SubmittedDateTo, 'yyyy-mm-dd'); 
    BEGIN
       FOR c_o IN c_orgs 
       LOOP
          DBMS_OUTPUT.put_line('Submitted date = '||c_o.submitted_date);
       END LOOP;
    END; 
    

    This ensures there is no errors in any implicit conversions and all conversions are obvious in their data type.

    “The question is: we are unable to find any information which clearly states that the Oracle 9i Optimizer has an issue with this kind of date arithmetic. Is that what’s happening here or is there something else going on?”

    I don’t think it is the optimiser, it could be the end product of your implicit conversions are causing the performance issues. As we do not have you NLS settings for dates etc from the Oracle database it’d be hard to tell but if using explicit conversions increases performance, then I’d suggest you use them (and it’s better pracitce too).

    Hope it helps, Ollie.

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

Sidebar

Related Questions

I have a query that basically combines tables of actions and selects from them
I have a query that looks like this SELECT * from myTable WHERE Date
I have a query that successfully grabs the unique products from my products table
I have have this query that i want to execute. SELECT warehouse.expiry_date, pharmacy.expiry_date, drugs.active_substance,
I have a query that is pulling users who liked a specific object from
Hi all I have an appointments table that has among other fields a DATE
I have 2 tables that I import to EF model. First table has a
I have a two tables. One has manufacturer information and includes the regions where
I have following sql query that take only 1 second to execute: select a.date,
I am using in C# MYsql .I have query that works if I run

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.