I am querying social security number data from a stored procedure and I would like to format it as a social security number in my stored procedure.
How can I format xxxxxxxxx like xxx-xx-xxxx in Oracle?
I am querying social security number data from a stored procedure and I would like to format it as a social security number in my stored procedure.
How can I format xxxxxxxxx like xxx-xx-xxxx in Oracle?
SSN formatting with TO_CHAR
update: thanks to Gary for pointing out that the '0' format character should be used rather than the '9' to preserve leading zeroes.
you could also use the concat operator
||
, which might be more readable.And if you'd like to check if the number consists of 9 digits before applying the format, then regular expressions can be of help:
Regards, Rob.