home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a524 / 37.ddi / demo / examp2.sql < prev    next >
Encoding:
Text File  |  1991-03-04  |  841 b   |  30 lines

  1. rem 
  2. rem $Header: examp2.sql,v 1002100.2 90/01/11 16:54:19 nsalah Exp $ examp2.sql Copyr (c) 1989 Oracle
  3. rem 
  4. rem V6PLS10021,DISK$DEV9:[PLS.DEMO.10021]
  5. /*
  6. ** This block debits account #3 by $500 only if there are enough funds
  7. ** to cover the withdrawal.
  8. **
  9. ** Copyright (c) 1989 by Oracle Corporation
  10. */
  11.  
  12. DECLARE
  13.     acct_balance    NUMBER(11,2);
  14.     ACCT            CONSTANT NUMBER(2) := 3;
  15.     DEBIT_AMT       CONSTANT NUMBER(5,2) := 500.00;
  16. BEGIN
  17.     SELECT bal INTO acct_balance FROM accounts
  18.         WHERE account_id = ACCT;
  19.     
  20.     IF acct_balance >= DEBIT_AMT THEN
  21.         UPDATE accounts SET bal = bal - DEBIT_AMT
  22.             WHERE account_id = ACCT;
  23.     ELSE
  24.         INSERT INTO temp VALUES
  25.             (ACCT, acct_balance, 'Insufficient funds.');
  26.                 -- insert account, current balance, and message
  27.     END IF;
  28. END;
  29. /
  30.