Set timestamp with milliseconds to default to 0 milliseconds [message #667396] |
Tue, 26 December 2017 16:55  |
 |
pallaviprakash
Messages: 2 Registered: February 2015
|
Junior Member |
|
|
Hi all,
I have a timestamp column in Oracle that has format 'MM/DD/YYYY HH24:MI.SxFF6'. The data looks like below:
11/09/1917 10:45:28.230000
10/19/2014 18:09:28.410000
12/19/2011 11:06:28.340000
I need the timestamp to retain the value except for getting the milliseconds which need to be defaulted to 000000. I tried query -
cast(to_char(Local_time, 'MM/DD/YYYY HH24:MI:SS') as timestamp(6))
But it is throwing error - "Not valid month"
Does anyone have any ideas on what I can try to get milliseconds to 0. I use Toad to query the table.
|
|
|
|
Re: Set timestamp with milliseconds to default to 0 milliseconds [message #667402 is a reply to message #667397] |
Wed, 27 December 2017 00:44  |
 |
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
How about CAST AS TIMESTAMP(0)?
SQL> with test
2 as (select to_timestamp ('11/09/1917 10:45:28.230000',
3 'mm/dd/yyyy hh24:mi:ss.ff')
4 col
5 from dual)
6 select col,
7 cast (col as timestamp (0)) res_1, --> "truncate" timestamp to seconds
8 to_char (cast (col as timestamp (0)), 'mm/dd/yyyy hh24:mi:ss.ff6') --> apply TO_CHAR to display it properly
9 res_2
10 from test;
COL RES_1 RES_2
--------------------------- --------------------------- ---------------------------
09.11.17 10:45:28,230000000 09.11.17 10:45:28 11/09/1917 10:45:28.000000
SQL>
P.S. BS, please read and follow the forum guidelines, How to use {code} tags and make your code easier to read
[Updated on: Wed, 27 December 2017 00:47] Report message to a moderator
|
|
|