How to Format a Number with a Comma in Oracle

When you use the TO_CHAR() function to format a number in Oracle, you use a format model to determine how the number should be formatted.

For example, you could format a number like 12,345.00 or like 12.345,00, depending on your locale.

The format model can include the G or D format elements to add a comma to a number. Which one you use depends on whether you want the comma as a thousands separator, or as a decimal character.

Alternatively, you can use an actual comma character (,) if you prefer, although this method is not locale aware like the G and D format elements are.

Continue reading

How to Add the Meridiem Indicator (AM/PM) to a Time Value in Oracle

When using the TO_CHAR() function to format a datetime value in Oracle Database, you can add the meridiem indicator (AM/PM) by simply adding either AM or PM to your format model.

Oracle then displays the appropriate meridiem indicator, depending on whether the time value is AM or PM.

You can provide it in any uppercase or lowercase, and with or without dots (e.g. AM, A.M. am, a.m, etc). Oracle will then display the meridiem indicator as specified.

Continue reading