Great number formatting trick
An excellent use of Oracle’s inbuilt formatting function – much simpler than parsing the input and multiple concatenation operators:
SELECT TO_CHAR(0408211234, 'FM0000G000G000','nls_numeric_characters=.-') phone from dual;
PHONE
-------------
0408-211-234
SSN formatting with TO_CHAR
Jeffrey Kemp
24 July 2009
SQL / stackoverflow / tips-&-tricks /
About Jeffrey Kemp
Application Designer & Developer at Oracle specialising in Oracle APEX (Application Express), Oracle SQL and PL/SQL. Oracle ACE Alumni ♠️. Piano player, father, husband, Christian.
The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
vkamys
16 May 2010 - 1:17 am
Hi Jeffrey
Your formatting trick is very clear and fine, but what to do if I want to have more complex mask based on various input strings 😉
Please check out my query
http://plsqlenergy.wordpress.com/2010/03/03/sql-model-clause-magic/
Jeffrey Kemp
18 May 2010 - 1:31 pm
Hi vkamys,
I would probably use a CASE structure to select the appropriate format mask depending on the input.
Jeff