Your question doesn't really make sense, but I understand why you're asking it.
Essentially, you're saying "I have this string "1"
but when I parse it as a number it has loads of numbers after the decimal: 1.0000000000000
. How can I store it without those extra zeroes"
And the answer is, you can't: 1
and 1.000000000
are the same thing, they're stored the same way, and it's not up to you to decide how it's stored. What you're seeing as an output of 1.000000000
is because you haven't asked for the internal numeric 1
to be output in a particular format (like $1.00), so you're just getting it in the default format for either the database or the query tool you're using
Ultimately, don't worry about it - hiding or showing those zeroes as a developer isn't going to matter a jot. Including them or not when you're querying your timestamp again isn't going to matter. When your front end app is dumping stuff to a report, it should retrieve the timestamp as is from Oracle and do the formatting itself; store $1 as a number 1, not a string "$1". When it comes time to put it on a report, format it as $1.00 in the code that makes the report.
If you're running queries that use the timestamp fields, you can compare with dates just fine... Just remember that dates and timestamps have a time component too, so query them using a range. For example to get all rows whose timestamp is today:
select * from t where mytimestamp >= trunc(sysdate) and mytimestamp < trunc(sysdate)+1
This is better than doing:
select * from t where trunc(mytimestamp) = trunc(sysdate)
Because trunc(mystimestamp) means you're manipulating table data to run your query. Unless you have specifically indexed the output of trunc(mytimestamp)
then this query could run like a dog, as an index on mytimestamp
column cannot be used if the query calls for table data to be manipulated before it is compared
It may help you to consider that internally, dates are typically stored as the number of days since a certain point in history. Times are fractions of a day. Internally 01-jan-1970 00:00
might be 0
, and 01-jan-1970 18:00
i.e. 6pm, is three quarters the way through the day, so it'll be stored as 0.75. 02-jan-1970
would hence be stored as 1. When you use trunc you chop off the decimal part. This is why trunc "removes" the time froma date. It doesn't "remove" it - you can't remove a time froma date, because everything that happens, happens at some point in time.. But it does reduce the time component to midnight, so trunc()ing all the adtes in a table effectively makes them all happen at midnight on the day in question.
Oracle can trunc to other things when it comes to dates, like truncing to the start of the month, but for now, remember that internally theyre fractional numbers, query them using ranges (so "between 01 jan 1970 and 02 jan 1970" is really saying "between 0 and 1" - which is what 0.75 i.e 6pm on 01 jan 1970, is)