Mask CNPJ in Firebird

Asked

Viewed 718 times

0

I need to mask my CPF field / CNPJ direct on Firebird, I tried the command below but it shows error, can anyone help me?

UPDATE EMPRESA
SET EMP_CPF_CNPJ = 
SUBSTRING(EMP_CPF_CNPJ from 1 for 2) + '.'
+ SUBSTRING(EMP_CPF_CNPJ from 3 for 3) + '.'
+ SUBSTRING(EMP_CPF_CNPJ from 6 for 3) + '/'
+ SUBSTRING(EMP_CPF_CNPJ from 9 for 4) + '-'
+ SUBSTRING(EMP_CPF_CNPJ from 13 for 2)
  • And why would you do that? The CNPJ consists only of numbers, these symbols are used to facilitate the reading by humans in the presentation, nothing more.

  • I had to change in the system to leave the mask fixed, only the data already registered does not appear in the fields even if they are masked

  • I believe that the best treatment in this case is, after recovering the database data, apply the mask through your application, before promoting the display of the data.

1 answer

2

In Firebird the concatenation symbol of Strings is || and not +, that was the error.

UPDATE EMPRESA SET
  EMP_CPF_CNPJ = SUBSTRING(EMP_CPF_CNPJ from 1 for 2) || '.' ||
                 SUBSTRING(EMP_CPF_CNPJ from 3 for 3) || '.' ||
                 SUBSTRING(EMP_CPF_CNPJ from 6 for 3) || '/' ||
                 SUBSTRING(EMP_CPF_CNPJ from 9 for 4) || '-' ||
                 SUBSTRING(EMP_CPF_CNPJ from 13 for 2)

Browser other questions tagged

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