How to do select using mask on output

1

I have a client table, and a cpfClient field of type varchar.

The cpf is stored without a mask. Ex: "00751595170"

I would like to make a select that formats the result by putting the masks. "007.515.951.70"

    
asked by anonymous 26.10.2015 / 23:40

1 answer

2

You can select parts of the SUBSTR field and concatenate CONCAT with the symbols to apply the formatting, eg:

SELECT 
CONCAT (
SUBSTR('11111111122',1,3),'.',
SUBSTR('11111111122',4,3),'.',
SUBSTR('11111111122',7,3),'-',
SUBSTR('11111111122',10)) as cpf;

SQL Fiddle

    
27.10.2015 / 00:28