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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:49:51+00:00 2026-06-03T13:49:51+00:00

Table my_table is: CREATE TABLE MY_TABLE( ID NUMBER NOT NULL, MY_DATE DATE NOT NULL);

  • 0

Table my_table is:

CREATE TABLE MY_TABLE(
ID        NUMBER  NOT NULL,
MY_DATE   DATE    NOT NULL);

Typing the following query:

select sysdate from dual

the result is:

10-MAG-12 21:22:32

note that mag = may.

Now, if I type this query:

select *
from my_table
where my_date <= sysdate

the result is:

9918    10-MAG-12 20:00:00
9915    10-MAG-12 21:00:00
9952    10-MAG-12 22:00:00
9951    10-MAG-12 23:00:00

Note that in my_table I have only these 4 records. Why I see all the records and not the first and second record only? Thanks.

I use Oracle SQL Developer.

Edit: please note that when I insert a record with PL/SQL I type something like:

nCount NUMBER;
myDate DATE;
stringDate VARCHAR2(255);
BEGIN
nCount := 0;
stringDate := substr(to_char(trunc(sysdate)),0,9);
myDate := to_date(stringDate || ' 20:00:00','dd-mm-yyyy hh24:mi:ss');
for t in (a cursor) loop
   insert into MY_TABLE(ID,MY_DATE)
   values (9918,myDate+(nCount/1440));
   nCount := nCount + 60;
end loop;
END;
  • 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-03T13:49:53+00:00Added an answer on June 3, 2026 at 1:49 pm

    I suspect that the data being stored in your table does not have a year of 2012. It probably has a year of 0012 (two thousand years ago).

    What do you see when you run the query

    SELECT id, to_char( my_date, 'dd-mm-yyyy hh24:mi:ss' )
      FROM my_table
    

    I expect that the year will be 0012 rather than 2012. The reason for that is that the code you’re using to insert the data is incorrectly converting a date to a string without using an explicit format mask then converts the string back to a date using an explicit format mask that happens not to match the session’s NLS_DATE_FORMAT. In general, if you ever find yourself converting a date to a string and back to a date, you’re probably doing something wrong. If you change your code to simply do date manipulation, it will be more efficient, more robust, and less error-prone.

    DECLARE
      nCount NUMBER;
      myDate DATE;
    BEGIN
      nCount := 0;
      myDate := trunc(sysdate) + interval '20' hour;
      for t in (a cursor) loop
         insert into MY_TABLE(ID,MY_DATE)
           values (9918,myDate+(nCount/1440));
         nCount := nCount + 60;
      end loop;
    END;
    

    Walking through why the original code goes wrong

    stringDate := substr(to_char(trunc(sysdate)),0,9);
    

    This takes SYSDATE and truncates it to midnight on the current day. So far, so good. Then, it calls TO_CHAR without an explicit format mask. This causes Oracle to use the session’s NLS_DATE_FORMAT, meaning that different users with different settings will get different results. If your session’s NLS_DATE_FORMAT happens to be ‘dd-mon-rr hh24:mi:ss’, which I’m guessing based on the query results you posted, that will mean that the string has a 2-digit year. Your SUBSTR appears to assume that the output has just a two-digit year (if you have a different NLS_DATE_FORMAT, your SUBSTR will generate different bugs such as potentially cutting off the 12 from a year of 2012 leaving a year of just 20).

    myDate := to_date(stringDate || ' 20:00:00','dd-mm-yyyy hh24:mi:ss');
    

    Assuming stringDate is something like 10-MAG-12, this next line generates a string 10-MAG-12 20:00:00 and then tries to convert it to a date using the format mask dd-mm-yyyy hh24:mi:ss. This assumes that the string has a 4-digit year so when it only finds 2-digits, it assumes that you meant the year 12, not the year 2012.

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

Sidebar

Related Questions

I've created list-range partitioned table: CREATE TABLE WHREST_PRT( RCNUM NUMBER NOT NULL, WHNUM NUMBER
My table: CREATE TABLE `beer`.`matches` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `hashId` int(10)
I created the following table for user to user subscriptions. CREATE TABLE IF NOT
Below is my table Schema: CREATE TABLE [dbo].[Sample]( [BoardId] [int] IDENTITY(1,1) NOT NULL, [UserCode]
Structure of my table : ID(int) | NUMBER(int) | CREATED_AT(date) If I have three
CREATE TABLE my_table ( fk INTEGER, field_1 INTEGER, field_2 INTEGER, field_3 INTEGER ) VALID:
If I had the following table. create_table :my_table, :id => false do |t| t.string
If my table looks like this: CREATE TABLE `daily_individual_tracking` ( `daily_individual_tracking_id` int(10) unsigned NOT
I'm getting odd results from a MySQL SELECT query involving a LEFT JOIN ,
I'm running a MySQL Query, here it is: CREATE TEMPORARY TABLE LeaderBoard ( `agent_name`

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.