user745235
user745235

Reputation:

Mask values on mysql database

I have a column with values like this:

01709100011

I need to transform it to:

017.091.0001-1

The values have always the same characters number.

Both columns are varchar

Thanks in advance for any help.

Upvotes: 0

Views: 1054

Answers (2)

David Bauer
David Bauer

Reputation: 399

SELECT CONCAT(SUBSTRING(test, 1,3),'.',SUBSTRING(test,4,3),'.',SUBSTRING(test,7,4),'-',SUBSTRING(test,11,1)) FROM test;

In the above example I used the table test and values in column test.

Upvotes: 1

KOGI
KOGI

Reputation: 3989

SELECT CONCAT_WS( "-", CONCAT_WS( ".", SUBSTRING( foo, 0, 3 ), SUBSTRING( foo, 3, 3 ), SUBSTRING( 6, 4 )), SUBSTRING( foo, 10 , 1 )) FROM bar WHERE 1=1;

Upvotes: 1

Related Questions