32
Finding information on how to calculate the CPF check digits is not difficult. Any Google search gives numerous results. Most are reliable and even have a well respected source which is the entry on CPF on Wikipedia (where unfortunately some previously existing codes have been removed). Some of the algorithms presented there are in better shape than others.
There is even how to do this in PL/SQL. But the doubt would be how to calculate the digits and get whether this calculation is valid or invalid using only the command SELECT
SQL, preferably with ANSI syntax or as close as possible. But the most important thing is the algorithm itself, more than a specific technical aspect.
The algorithm in this form is useful when you don’t have access to a database system with Stored Procedures or privileges to create an SP in a database.
If it helps, initially the data format contains no separator signals.
This is a scenario where it is not known whether the data contained in the database is reliable or not. Assemble a SELECT
in an algorithm, which is usually done using more complex code, as demonstrated in Wikipedia, is not something so trivial.
Alternatives that help solve the fashion problem correct will be appreciated. Obviously there can be false positive or negative, which would destroy the purpose.
I do not know where there is official documentation on the subject. I have searched enough and did not find, at least in the obvious places. It’s amazing how lacking official source in all the places where you teach how to do the calculation. But it is something well known in Brazil.
No matter the check the cadastral situation in the IRS, only if the digits are correct.
This question has been asked before here and has been removed due to problems in its conception, aggressiveness generated in the comments and mainly for having incorrect answers. Following Zuul’s request on http://meta.pt.stackoverflow.com/a/1143/101 (read the whole discussion, it is useful for learning the whole community) here is an opportunity for the question to have a correct answer, since it is very useful to the site, either to give initial information about the calculation or to know an algorithm optimized to "fit" into a SELECT. I hope I’ve helped in the little time I have available.
– Maniero
I am happy to see this question back, it was frustrating the feeling of effort lost in the other, mainly for having developed the select and having done several tests to get the answer. And not only that, I imagine this is a VERY common problem for Brazilian developers! Too bad you can vote up once.
– Bacco
@excellent bigown have recovered the question.
– Sergio
very nice to have the question helping here again hahaha
– aasc
The algorithm behind Cpf number creation can be better understood here at http://www.geradorcpf.com/algoritmo_do_cpf.htm
– Manoel Jr