简体   繁体   中英

comparing the java current timestamp againt column in oracle db

I have column in oracle DB which is stored values in this format 

'20-DEC-2022 02.04.19.2424 PM'
'02-DEC-2022 03.14.19.1524 AM'
'02-NOV-2022 11.14.19.1524 PM'
'02-MAY-2022 08.14.19.1524 AM'

From java I need to compare with system time against emp_updt_timestmp column.Is below query fetches correct results?

I will pass the current time from java['20-12-2022 04.02.12 PM'].Do I need to pass in this format only from Java.Please clarify.

.select * from emp where emp_updt_timestmp >= to_timestamp('20-12-2022 04.02.12 PM','dd-mm-yyyy hh.mi.ss AM')

Yes, the query you provided should be able to fetch the correct results. The to_timestamp function converts string representation of a date & time ('21-12-2022 11.09.12 AM') to a timestamp data type, which is what the emp_updt_timestmp column is expected to be.

It's important to note that the format string ('dd-mm-yyyy hh.mi.ss AM') you provided should match the format of the string representation of the date and time you are trying to convert.

In this case, the string representation is in the format 'dd-mon-yyyy hh.mi.ss.ff AM', where 'mon' represents the month abbreviation (eg, 'DEC' for December). 'ff' represents the fractional seconds. 'AM' or 'PM' indicates whether the time is in the morning or afternoon.

If the format of string representation of date and time you are trying to convert doen't match format string provided to to_timestamp function, the function will not be able to correctly convert the string to a timestamp and you will get an error.

For example: if the string representation of the date and time was in the format 'yyyy-mm-dd hh:mi:ss', you would need to use a format string like 'yyyy-mm-dd hh:mi:ss' in the to_timestamp function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM