Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE PROCEDURE abc.transferencia (
- in_origem_id INT,
- in_destino_id INT,
- in_valor NUMERIC
- )
- LANGUAGE 'plpgsql'
- AS $$
- BEGIN
- -- Cliente origem
- UPDATE abc.conta SET saldo = saldo - in_valor
- WHERE id = in_origem_id;
- -- Cliente destino
- UPDATE abc.conta SET saldo = saldo + in_valor
- WHERE id = in_destino_id;
- RAISE NOTICE '[origem %] --> % --> [destino %]',
- in_origem_id, in_valor, in_destino_id;
- COMMIT;
- END;
- $$;
- -- Chamando procedure que possui apenas parâmetros de entrada
- CALL abc.transferencia(1, 2, 500);
- -- Verificando os dados
- SELECT * FROM abc.conta;
Advertisement
Add Comment
Please, Sign In to add comment