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

  1. rem
  2. rem $Header: examp8.sql,v 1002800.2 90/01/11 16:56:54 nsalah Exp $ examp8.sql Copyr (c) 1989 Oracle
  3. rem
  4. rem V6PLS10028,DISK$DEV2:[PLS1FREEZE.DEMO.10028]
  5. /*
  6. ** This block calculates the ratio between the X and Y columns of
  7. ** the RATIO table.  If the ratio is greater than 0.72, then it
  8. ** inserts the ratio into RESULT_TABLE.  Otherwise, it does nothing.
  9. **
  10. ** If the denominator is 0, then ZERO_DIVIDE will be raised, and a
  11. ** 0 will be inserted into RESULT_TABLE as the ratio.
  12. **
  13. ** Copyright (c) 1989 by Oracle Corporation
  14. */
  15.  
  16. DECLARE
  17.     numerator        NUMBER;
  18.     denominator        NUMBER;
  19.     the_ratio       NUMBER;
  20.     LOWER_LIMIT        CONSTANT NUMBER := 0.72;
  21.     SAMP_NUM        CONSTANT NUMBER := 132;
  22. BEGIN
  23.     SELECT x, y INTO numerator, denominator FROM result_table
  24.         WHERE sample_id = SAMP_NUM;
  25.     the_ratio := numerator/denominator;
  26.     IF the_ratio > LOWER_LIMIT THEN
  27.         INSERT INTO ratio VALUES (SAMP_NUM, the_ratio);
  28.     ELSE
  29.         INSERT INTO ratio VALUES (SAMP_NUM, -1);
  30.     END IF;
  31.     COMMIT;
  32. EXCEPTION
  33.     WHEN ZERO_DIVIDE THEN
  34.         INSERT INTO ratio VALUES (SAMP_NUM, 0);
  35.         COMMIT;
  36.     WHEN OTHERS THEN
  37.         ROLLBACK;
  38. END;
  39. /
  40.