简体   繁体   中英

JOOQ Issue: AM/A.M. or PM/P.M. required

I am using JOOQ 3.4.1 as middleware to communicate with Oracle Database but when I write the below Query in my code I got SqlDataException: AM/AM or PM/PM required.

select 0 prodid, cast(((cast('31-DEC-' as varchar2(4000)) || cast(YearForBilling as varchar2(4000))) || ' 12.59.00.000000000 PM ') as timestamp) theDate  0 Balance from ProductDetails where productRSN = 71 
group by YearForBilling

Can anybody help me out to fix that issue?

Always try avoiding local date time formats

I would never rely on locale-dependent formatted date and timestamp strings. Never . You never know if those settings change at some point of time, eg as the system default, or as a session setting, etc. Don't rely on it. Don't .

If you can, use SQL standard timestamp literals that have absolutely no dependency on your NLS settings ( I've blogged about this here ). For instance:

TIMESTAMP '2016-12-31 23:59:00.0'

In your case, you're creating a date dynamically, so timestamp literals won't work. But still, please use ISO 8601 date formatting, as such

TO_TIMESTAMP(YearForBilling || '-12-31 23:59:00', 'YYYY-MM-DD HH24:MI:SS')

The TO_TIMESTAMP() function is described here .

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