• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Oracle date storage?

 
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am a java developer i am wonder how date is stored in back end oracle. I just stored two dates like this,

In DOB column it is storing like "1-1-88" in both columns. But when getting date field it is getting the correct data. How it is happening, Is the any buffer to store the era or something..
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DATE in Oracle is stored in some internal ("binary") form. When handled by external systems, it is converted to/from the internal representation from/to the representation of the external system.

mallikarjun dontamsetti wrote:In DOB column it is storing like "1-1-88" in both columns.


I assume that you're using something like SQL*Plus or SQL Developer to display these values. In these cases, the date is converted to text for display using representation ("format") defined by your environment. I guess that your environment defines date format as something like DD-MM-YY (that is, two digit years only), which means that 1-1-1988 and 1-1-1788 get converted to the same text, though they are different in the database's native format.

If you're using SQL*Plus, you can execute the alter session set NLS_DATE_FORMAT='DD-MM-YYYY'; command; that will cause the date values to be printed with four digit year and you'll be able to distinguish the two dates apart even in the textual representation.

Meanwhile, there is a subtle bug in your code:
These commands cause the value for column dob to be implicitly converted using the current value of the NLS_DATE_FORMAT setting, which may differ on different computers or be influenced by other circumstances. If these commands were actually issued from Java, you should use bind variables instead; this avoids the database conversion from text do date altogether. If this is a part of some SQL script, you should use to_date function to explicitly define the date format to be used:
In production code, this is a must; I'd suggest using this even for just testing/experimental code. You'll eliminate possible errors from the beginning and learn a useful habit of specifying the conversion format everywhere.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic