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

  • Home
  • SEARCH
  • 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 8042107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:27:51+00:00 2026-06-05T04:27:51+00:00

I am trying to optimize a simple SQL query and was wondering if anyone

  • 0

I am trying to optimize a simple SQL query and was wondering if anyone has any suggestions. I am developing using Oracle SQL Developer (which I don’t like) on an Oracle 11g database. The query I am using is:

SELECT count(*) 
FROM my_table 
WHERE my_date
BETWEEN TO_DATE('2012-5-09T05.00.00','YYYY-MM-DD"T"HH24:MI:SS') 
AND TO_DATE('2012-5-10T04.59.59','YYYY-MM-DD"T"HH24:MI:SS') 
AND my_code='33' 
GROUP BY my_code;

Also, I want to be able to use this query dynamically by changing the part of the date to be whatever the current date is, but I want to be able to specify the hour. So I want to be comparing something like:

getdate() + 'T05.00.00'

I have no idea how to do this and the getdate() function doesn’t seem to work in SQL Developer/I don’t know how to use it correctly.

So what I’m looking for is optimization suggestions and pointers on how to just dynamically change the day-month-year part of the date I want to constrain my results to. 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-06-05T04:27:53+00:00Added an answer on June 5, 2026 at 4:27 am

    To get current date, you can use SYSDATE. To add x number of hours to it, you can add x/24. So something like this:

    Example: Get current date + 5 hours

     SELECT SYSDATE + 5/24 FROM dual
    

    So in your example:

    SELECT count(*) 
    FROM my_table 
    WHERE my_date
    BETWEEN sysdate
    AND sysdate + 5/24 -- if you want 5 hours ahead, for example
    AND my_code='33' 
    GROUP BY my_code;
    

    If you want to be able to change the number of hours, you could make this code into a function, and pass in the hours and code as variables.

    Something like this:

    CREATE FUNCTION myfunc
    (
       p_num_hours INT
     , p_my_code VARCHAR
    ) RETURN INT
    AS
      l_ret INT;
    BEGIN
       SELECT count(*) 
       INTO l_ret
       FROM my_table 
       WHERE my_date
       BETWEEN sysdate
       AND sysdate + p_num_hours/24
       AND my_code=p_my_code 
    
       RETURN l_ret;
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to optimize this mysql query using EXPLAIN. Can somebody please help me
I'm trying to optimize a query which uses a view in MySQL 5.1. It
I'm trying to optimize this query, and as simple as it sounds, I'm having
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I'm trying to optimize my C++ code. I've searched the internet on using dynamically
I am trying to optimize a query that does something like this: SELECT ...
I've trying to optimize a query on MySQL that takes around 15-20 seconds to
I'm trying to execute a simple test code: using System; using System.IO; using System.Linq;
I'm trying to optimize the reflection utilization in my code and I was wondering
I'm trying to optimize my SQL queries and I always come back to this

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.