Home » SQL & PL/SQL » SQL & PL/SQL » detect and fix the negative time in oracle
detect and fix the negative time in oracle [message #516240] Fri, 15 July 2011 12:20 Go to next message
casttree
Messages: 83
Registered: August 2008
Member
I found the data in DB with negative time as below

Quote:

1 SELECT
2 c.time
3 FROM partition c
4 WHERE
5* c.time < to_date('0001-01-01','YYYY-MM-DD')
SQL> /

DEACTIVATION_TIME
------------------------------------------------------------------------
17-JUN-08 04.06.22.893 PM


The data type for c.time is Timestamp.


When I use JDBC to retrieve the data and convert it to mill seconds, and it also shows as negative time.

My question is the retrieved time doesn't show the negative date, but obvious it is a BC date and earlier than 0001-01-01.

1. How can we detect/show the date to show correctly for the BC date without checking c.time < to_date('0001-01-01','YYYY-MM-DD')? (I am wondering if there is format configuation to show the time like 17-JUN-08 04.06.22.893 PM BC, or somthing to show the time is negative )

2.how could we fix it negative time to positive ?


Thanks


Thanks


Re: detect and fix the negative time in oracle [message #516242 is a reply to message #516240] Fri, 15 July 2011 12:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68767
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
How can we detect/show the date to show correctly for the BC date without checking c.time

Use TO_CHAR with the appropriate format mask.

Quote:
how could we fix it negative time to positive ?

Apply a correct rule for this.
Which (correct) date should be " 17-JUN-08 04.06.22.893 PM BC"?

Regards
Michel
Re: detect and fix the negative time in oracle [message #516247 is a reply to message #516242] Fri, 15 July 2011 13:06 Go to previous messageGo to next message
casttree
Messages: 83
Registered: August 2008
Member
Thanks, Michel,

Now I can see the time as "2008-06-17 BC" with to_char. Could you give me more information what rule we can apply to prevent the negative date like this to be inserted to oracle Database?

Thanks
Re: detect and fix the negative time in oracle [message #516249 is a reply to message #516247] Fri, 15 July 2011 13:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68767
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Add a check constraint to your column, something like:
CHECK (extract(year from time) > 0)

Regards
Michel
Re: detect and fix the negative time in oracle [message #516251 is a reply to message #516247] Fri, 15 July 2011 13:40 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Could you give me more information what rule we can apply to prevent the negative date like this to be inserted to oracle Database?
CHECK CONSTRAINT
Re: detect and fix the negative time in oracle [message #516344 is a reply to message #516249] Sat, 16 July 2011 18:25 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3305
Registered: January 2010
Location: Connecticut, USA
Senior Member
Michel Cadot wrote on Fri, 15 July 2011 14:24
CHECK (extract(year from time) > 0)


Or

CHECK(time >= TIMESTAMP '1-1-1 0:0:0')


SY.

[Updated on: Sat, 16 July 2011 18:30]

Report message to a moderator

Re: detect and fix the negative time in oracle [message #516346 is a reply to message #516344] Sat, 16 July 2011 19:17 Go to previous message
casttree
Messages: 83
Registered: August 2008
Member
Thanks a lot for all information!
Previous Topic: Muttating Trigger
Next Topic: SQL IN clause versus = operator
Goto Forum:
  


Current Time: Sun Aug 24 13:11:28 CDT 2025