When using the TO_CHAR() function in Oracle Database, you can use the RN format element to return the number as roman numerals. Using lowercase (rn) returns the roman numerals in lowercase.
Example
Here’s an example to demonstrate:
SELECT TO_CHAR(748, 'fmRN') FROM DUAL;
Result:
DCCXLVIII
Note that I’m using the fm format modifier to suppress any padding that might be applied.
Here’s what happens when I remove the fm format modifier:
SELECT TO_CHAR(748, 'RN') FROM DUAL;
Result:
DCCXLVIII
Lowercase
Using a lowercase rn returns the roman numerals in lowercase:
SELECT TO_CHAR(748, 'fmrn') FROM DUAL;
Result:
dccxlviii
Out of Range
When using the RN/rn format element, the value must be between 1 and 3999.
Here’s what happens when I provide a number outside of this range:
SELECT TO_CHAR(4000, 'fmrn') FROM DUAL;
Result:
###############
But reducing it by 1 is fine:
SELECT TO_CHAR(3999, 'fmrn') FROM DUAL;
Result:
mmmcmxcix
And here’s a negative value:
SELECT TO_CHAR(-1, 'fmrn') FROM DUAL;
Result:
###############