Thursday, October 31, 2019

Oracle to_char date language

Example of select using to_date while changing the language of the output (eg. OCT in english instead of OKT in German).

select distinct(a.position_nbr),
       to_char(a.effdt,'DD-MON-YYYY','nls_date_language=English') as EFFDT,
       a.descr from ps_position_data a
where effdt = (select max(effdt) from ps_position_data sa where sa.position_nbr = a.position_nbr and effdt <= sysdate)

and eff_status = 'A' and posn_status = 'A'

Format specifiers table, for reference:
Oracle TO_CHAR Format Specifier
YYYY 4 digit year
YY 2 digit year
MON Abbreviated month (Jan - Dec)
MONTH Month name (January - December)
MM Month (1 - 12)
DY Abbreviated day (Sun - Sat)
DD Day (1 - 31)
HH24Hour (0 - 23)
HH or HH12 Hour (1 - 12)
MI Minutes (0 - 59)
SS Seconds (0 - 59)