DECLARE acct_balance NUMBER(11, 2); acct CONSTANTNUMBER(4) := 3; debit_amt CONSTANTNUMBER(5, 2) := 500.00; BEGIN SELECT bal INTO acct_balance FROM accounts WHERE account_id = acct FORUPDATEOF bal;
IF acct_balance >= debit_amt THEN UPDATE accounts SET bal = bal - debit_amt WHERE account_id = acct; ELSE INSERTINTO temp VALUES (acct, acct_balance, 'Insufficient funds'); -- insert account, current balance, and message ENDIF;
CASE WHEN shape = 'square'THEN area := side * side; WHEN shape = 'circle'THEN BEGIN area := pi *(radius * radius); DBMS_OUTPUT.put_line('Value is not exact because pi is irrational.'); END; WHEN shape = 'rectangle'THEN area := LENGTH * width; ELSE BEGIN DBMS_OUTPUT.put_line('No formula to calculate area of a' || shape); RAISE PROGRAM_ERROR; END; ENDCASE;
PROCEDURE award_bonus(emp_id NUMBER) IS bonus REAL; comm_missing EXCEPTION; BEGIN-- executable part starts here SELECT comm * 0.15 INTO bonus FROM emp WHERE empno = emp_id;
IF bonus ISNULLTHEN RAISE comm_missing; ELSE UPDATE payroll SET pay = pay + bonus WHERE empno = emp_id; ENDIF; EXCEPTION-- exception-handling part starts here WHEN comm_missing THEN ... END award_bonus;