-
Notifications
You must be signed in to change notification settings - Fork 0
/
2625 - Máscara de CPF.sql
50 lines (42 loc) · 1.37 KB
/
2625 - Máscara de CPF.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--- URI Online Judge SQL
--- Copyright URI Online Judge
--- www.urionlinejudge.com.br
--- Problem 2625
CREATE DATABASE URI_Problem_2625;
USE URI_Problem_2625;
CREATE TABLE customers (
id numeric PRIMARY KEY,
name varchar(255),
street varchar(255),
city varchar(255),
state char(2),
credit_limit numeric
);
CREATE TABLE natural_person (
id_customers numeric REFERENCES customers (id),
cpf char (14)
);
INSERT INTO customers (id, name, street, city, state, credit_limit)
VALUES
(1, 'Nicolas Diogo Cardoso', 'Acesso Um', 'Porto Alegre', 'RS', 475),
(2, 'Cecília Olivia Rodrigues', 'Rua Sizuka Usuy', 'Cianorte', 'PR', 3170),
(3, 'Augusto Fernando Carlos Eduardo Cardoso', 'Rua Baldomiro Koerich', 'Palhoça', 'SC', 1067),
(4, 'Nicolas Diogo Cardoso', 'Acesso Um', 'Porto Alegre', 'RS', 475),
(5, 'Sabrina Heloisa Gabriela Barros', 'Rua Engenheiro Tito Marques Fernandes', 'Porto Alegre', 'RS', 4312),
(6, 'Joaquim Diego Lorenzo Araújo', 'Rua Vitorino', 'Novo Hamburgo', 'RS', 2314);
INSERT INTO natural_person (id_customers, cpf)
VALUES
(1, '26774287840'),
(2, '97918477200');
/* Execute this query to drop the tables */
-- DROP TABLE natural_person, customers; --
/*RESOLUÇÃO DO PROBLEMA*/
SELECT CONCAT(
SUBSTRING(cpf,1,3),
'.',
SUBSTRING(cpf,4,3) ,
'.',
SUBSTRING(cpf,7,3) ,
'-',
SUBSTRING(cpf,10,2)) AS 'CPF'
FROM natural_person;