如何将数字格式化为xxx-xx-xxxx? [英] How can I format a number as xxx-xx-xxxx?

查看:134
本文介绍了如何将数字格式化为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.

如何在Oracle中像xxx-xx-xxxx一样格式化xxxxxxxxx?

How can I format xxxxxxxxx like xxx-xx-xxxx in Oracle?

推荐答案

使用TO_CHAR的SSN格式

SELECT TO_CHAR(012345678, '000g00g0000','nls_numeric_characters=.-') ssn from dual;

SSN
-----------
012-34-5678  

更新:感谢Gary指出应使用'0'格式字符而不是'9'保留前导零.

update: thanks to Gary for pointing out that the '0' format character should be used rather than the '9' to preserve leading zeroes.

这篇关于如何将数字格式化为xxx-xx-xxxx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆