Assuming the value entered is numeric rather than DATE, you can use TO_CHAR , but you need to convert the numeric value to a string, then DATE (Julian) before final formatting:
SELECT TO_CHAR(TO_DATE('1', 'dd'), 'ddth') FROM DUAL
Result:
01st
When testing, using 'd' for the format does not return the expected results, because the value is interpreted as a Julian date. Either adjust the output to remove the initial zero, or specify the full date string (it does not matter for TO_CHAR, because it is only interested in the day of the month):
SELECT TO_CHAR(TO_DATE('1900-01-01', 'YYYY-MM-dd'), 'dth') FROM DUAL
Since calendar days end in 31, use the year value to process numbers greater than 31 instead:
SELECT TO_CHAR(TO_DATE('32-01-01', 'YYYY-MM-dd'), 'yyth') FROM DUAL
Result:
32nd
source share