-
Notifications
You must be signed in to change notification settings - Fork 0
/
Procedure.txt
57 lines (46 loc) · 1.52 KB
/
Procedure.txt
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
51
52
53
54
55
56
57
DELIMITER $
CREATE OR REPLACE PROCEDURE usuario(
IN id INT,
IN nome VARCHAR(100),
IN cpf VARCHAR(20),
IN email VARCHAR(50),
IN matricula VARCHAR(20),
IN nivel VARCHAR(15),
IN st CHAR(1))
BEGIN
DECLARE variavel VARCHAR(1000) DEFAULT "";
IF id != 0 THEN
SET variavel = CONCAT("WHERE usuario_id = ", id);
ELSE
SET variavel = "WHERE usuario_id > 0";
END IF;
IF nome != "" THEN
SET variavel = CONCAT(variavel, " AND usuario_nome = ", nome);
END IF;
IF cpf != "" THEN
SET variavel = CONCAT(variavel, " AND usuario_cpf = ", cpf);
END IF;
IF email != "" THEN
SET variavel = CONCAT(variavel, " AND usuario_email = ", email);
END IF;
IF matricula != "" THEN
SET variaveL = CONCAT(variavel, " AND usuario_matricula = ", matricula);
END IF;
IF nivel != "" THEN
SET variavel = CONCAT(variavel, " AND usuario_nivel = ", nivel);
END IF;
IF st != "" THEN
SET variavel = CONCAT(variavel, " AND usuario_status = ", st);
END IF;
SELECT usuario_id AS ID,
usuario_nome AS Nome,
usuario_cpf AS CPF,
usuario_email AS 'e-mail',
usuario_matricula AS Matrícula,
usuario_nivel AS 'Nível de acesso',
usuario_status AS 'Status'
FROM usuarios
HAVING (SELECT variavel);
END $
DELIMITER ;
CALL usuario("", "", "", "", "", "", "")