Advertisement
Rahmadnet

PostgreSQL CREATE PROCEDURE

Jul 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. create table akun
  2. (id int generated by default as identity primary key,
  3. name char (100) not null,
  4. balance dec (15,2) not null);
  5.  
  6. insert into akun (name,balance)
  7. values('Andari', 100000);
  8.  
  9. select * from akun;
  10.  
  11. create or replace procedure transfer(int, int, dec)
  12. language plpgsql
  13. as $$
  14. begin
  15.    
  16.     update akun
  17.     set balance = balance - $3
  18.     where id = $1
  19.    
  20.     update akun
  21.     set balance = balance + $3
  22.     where id = $2;
  23.  
  24. commit;
  25. end;
  26. $$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement