fahadkalil

plpgsql_ex_abc_transferencia

Oct 16th, 2025 (edited)
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 0.61 KB | Source Code | 0 0
  1. CREATE OR REPLACE PROCEDURE abc.transferencia (
  2.   in_origem_id INT,
  3.   in_destino_id INT,
  4.   in_valor NUMERIC
  5. )
  6. LANGUAGE 'plpgsql'
  7. AS $$
  8. BEGIN
  9.   -- Cliente origem
  10.   UPDATE abc.conta SET saldo = saldo - in_valor
  11.   WHERE id = in_origem_id;
  12.  
  13.   -- Cliente destino
  14.   UPDATE abc.conta SET saldo = saldo + in_valor
  15.   WHERE id = in_destino_id;  
  16.  
  17.   RAISE NOTICE '[origem %] --> % --> [destino %]',
  18.   in_origem_id, in_valor, in_destino_id;
  19.  
  20.   COMMIT;
  21. END;
  22. $$;
  23.  
  24. -- Chamando procedure que possui apenas parâmetros de entrada
  25. CALL abc.transferencia(1, 2, 500);
  26.  
  27. -- Verificando os dados
  28. SELECT * FROM abc.conta;
Advertisement
Add Comment
Please, Sign In to add comment