-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIF-THEN-ELSEIF.sql
More file actions
42 lines (33 loc) · 922 Bytes
/
Copy pathIF-THEN-ELSEIF.sql
File metadata and controls
42 lines (33 loc) · 922 Bytes
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
-- Controle de Fluxo "IF/THEN/ ELSEIF".
IF condition THEN
if_stantements;
ELSEIF
elseif_stantements;
ELSEIF
elseif_stantements;
(....)
ELSE
else_stantements;
END IF
-- EXEMPLO:
DROP procedure IF EXISTS `achar_status_preco`;
DELIMITER $$
USE `sucos_vendas`$$
CREATE PROCEDURE `achar_status_preco` (vProduto varchar(50))
BEGIN
declare vPreco float;
declare vMensagem varchar(30);
select PRECO_DE_LISTA into vPreco from tabela_de_produtos where CODIGO_DO_PRODUTO = vProduto;
IF vPreco >= 12 THEN
set vMensagem = 'Produto Caro!';
ELSEIF vPreco >= 7 and vPreco < 12 THEN
set vMensagem = 'Produto Em Conta!';
ELSE
set vMensagem = 'Produto Barato!';
END IF;
select vMensagem;
END$$
DELIMITER ;
call call achar_status_preco('1000889'); --RESULTADO = Produto Barato!
call call achar_status_preco('1086543'); --RESULTADO = Produto Em Conta!
call call achar_status_preco('326779'); --RESULTADO = Produto Caro!