How can I format a number as xxx-xx-xxxx?
问题 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? 回答1: SSN formatting with TO_CHAR SELECT TO_CHAR(012345678, '000g00g0000','nls_numeric_characters=.-') ssn from dual; SSN ----------- 012-34-5678 update: thanks to Gary for pointing out that the '0' format character should be used rather than the '9' to preserve leading zeroes. 回答2: you could