About the RM Format Element in Oracle

In Oracle Database, the RM format element allows you to return the month in roman numerals when using the TO_CHAR() function.

You can also use the fm modifier to suppress any padding.

Example

Here’s an example to demonstrate:

SELECT 
    TO_CHAR(date '2030-04-08', 'DD-RM-YYYY')
FROM DUAL;

Result:

08-IV  -2030

In this case, the month number is 04, and the roman numeral equivalent is IV.

Lowercase vs Uppercase

You can use rm (in lowercase) to return the roman numerals in lowercase:

SELECT 
    TO_CHAR(date '2030-04-08', 'DD-rm-YYYY')
FROM DUAL;

Result:

08-iv  -2030

Remove Padding

By default, the month is padded with trailing blanks to the length of 4, which is the length of viii. We can see that in the above examples.

To suppress the padding, use the fm format modifier:

SELECT 
    TO_CHAR(date '2030-04-08', 'DD-fmRM-YYYY')
FROM DUAL;

Result:

08-IV-2030

Note that this will suppress any padding from all subsequent elements. In our case, padding will also be suppressed from the year. If our year is less than four digits long, then it won’t have any leading zeros:

SELECT 
    TO_CHAR(date '0030-04-08', 'DD-fmRM-YYYY')
FROM DUAL;

Result:

08-IV-30

If we want to retain the leading zeros, we can prefix YYYY with fm:

SELECT 
    TO_CHAR(date '0030-04-08', 'DD-fmRM-fmYYYY')
FROM DUAL;

Result:

08-IV-0030

The fm modifier effectively acts like a switch that enables/disables fill mode.

If we want to suppress all padding in the date, we can simply prepend the whole format model with a single fm:

SELECT 
    TO_CHAR(date '0030-04-08', 'fmDD-RM-YYYY')
FROM DUAL;

Result:

8-IV-30