But prior oracle they did not support the use sql expressions
|
|||
---|---|---|---|
156 |
|
---|
Writing Your Own Functions
This is the Title of the Book, eMatter Edition | ||
---|---|---|
Copyright © 2001 O’Reilly & Associates, Inc. All rights reserved. | ||
![]() |
157 | |||
---|---|---|---|
|
To get the minimum price for a given page count, you need to find the row with | ||
---|---|---|
the highest page count that is less than or equal to the number of pages in the | ||
book. For example, any page count from 400 to 499 carries a minimum price of | ||
$34.95. At 500 pages, the minimum price jumps to $39.95. The following stored | ||
PL/SQL function takes current price and page counts as parameters, queries the |
price_page_threshold table, and returns the greater of the current price or the mini-mum price:
CREATE OR REPLACE FUNCTION price_check
(price_in NUMBER, pages_in NUMBER)
RETURN NUMBER IS
min_price NUMBER;
BEGIN
/* Retrieve the mininum price for the number of pages in question. */ SELECT ppt_min_price INTO min_price
FROM price_page_threshold
WHERE pages_in >= ppt_pages
AND ppt_pages = (
SELECT MAX(ppt_pages)
FROM price_page_threshold
WHERE pages_in >= ppt_pages);
This is the Title of the Book, eMatter Edition | ||
---|---|---|
Copyright © 2001 O’Reilly & Associates, Inc. All rights reserved. | ||
![]() |