How to make select using mask on output

Asked

Viewed 1,176 times

1

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

Cpf is stored without mask. Ex:"00751595170"

I would like to do a select that format the result by putting on the masks. "007.515.951.70"

  • Why not put the mask on the front end with Javascript or some function in your View? You really need to put the mask inside select?

  • Yes, I do. Thank you.

1 answer

2


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

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

SQL Fiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.