Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION aula03.f_desconto(in_valor NUMERIC, in_desconto NUMERIC)
- RETURNS NUMERIC AS $$
- DECLARE
- -- Declaracao de variavel
- v_resultado NUMERIC := 0.0;
- BEGIN
- IF in_desconto <= 100 AND in_desconto >= 0 THEN
- v_resultado := in_valor * (1.0 - (in_desconto / 100));
- ELSE
- RAISE EXCEPTION 'Desconto inválido'
- USING HINT = 'Valores aceitos: entre 0.0 e 100.0';
- END IF;
- RETURN v_resultado;
- END;
- $$ LANGUAGE plpgsql;
- /* Chamando a function */
- SELECT aula03.f_desconto(100, 10);
- --SELECT aula03.f_desconto(150, 101);
- --SELECT TRUNC(aula03.f_desconto(100, 10), 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement