Method Example I
01 | SQL > CREATE OR REPLACE TYPE book_t AS OBJECT ( |
05 | 5 stock_qty NUMBER (4), |
06 | 6 MEMBER FUNCTION get_discount RETURN NUMBER ); |
10 | SQL > CREATE OR REPLACE TYPE BODY book_t AS |
11 | 2 MEMBER FUNCTION get_discount RETURN NUMBER IS |
12 | 3 clearance number := 40; |
13 | 4 nominal number := 10; |
15 | 6 IF stock_qty < 100 THEN |
16 | 7 RETURN round ( ( price * nominal / 100 ), 2 ); |
18 | 9 RETURN round ( ( price * clearance / 100 ), 2 ); |
26 | SQL > CREATE TABLE books OF book_t; |
30 | SQL > INSERT INTO books VALUES ( |
31 | 2 book_t( 'Oracle 12c: The Complete Reference' , |
32 | 3 'Kevin Loney' , 44.99, 345 ) ); |
36 | SQL > SELECT b.price, b.price - b.get_discount( ) |
37 | 2 FROM books b WHERE author = 'Kevin Loney' ; |
39 | PRICE B.PRICE-B.GET_DISCOUNT( ) |
44 | SQL > VARIABLE x NUMBER ; |
47 | 2 SELECT b.price - b.get_discount( ) INTO :x |
48 | 3 FROM books b WHERE author = 'Kevin Loney' ; |
52 | PL/ SQL procedure successfully completed. |
|
ROUND(n [, m])
returns
n
rounded to
m
places right of the decimal point; e.g.,
ROUND(15.193, 1) = 15.2
.
I’m not a big fan of stairs. They are always up to something.
|