RESTRICT_REFERENCES pragma.
SQL>
SQL> CREATE TABLE lecturer (
2 id NUMBER(5) PRIMARY KEY,
3 first_name VARCHAR2(20),
4 last_name VARCHAR2(20),
5 major VARCHAR2(30),
6 current_credits NUMBER(3)
7 );
Table created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10001, 'Scott', 'Lawson','Computer Science', 11);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major, current_credits)
2 VALUES (10002, 'Mar', 'Wells','History', 4);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10003, 'Jone', 'Bliss','Computer Science', 8);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10004, 'Man', 'Kyte','Economics', 8);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10005, 'Pat', 'Poll','History', 4);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10006, 'Tim', 'Viper','History', 4);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10007, 'Barbara', 'Blues','Economics', 7);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10008, 'David', 'Large','Music', 4);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10009, 'Chris', 'Elegant','Nutrition', 8);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10010, 'Rose', 'Bond','Music', 7);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10011, 'Rita', 'Johnson','Nutrition', 8);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10012, 'Sharon', 'Clear','Computer Science', 3);
1 row created.
SQL>
SQL>
SQL> CREATE OR REPLACE PACKAGE StudentOps AS
2 FUNCTION FullName(p_ID IN lecturer.ID%TYPE)
3 RETURN VARCHAR2;
4 PRAGMA RESTRICT_REFERENCES(FullName, WNDS, WNPS, RNPS);
5
6 FUNCTION NumHistoryMajors
7 RETURN NUMBER;
8 PRAGMA RESTRICT_REFERENCES(NumHistoryMajors, WNDS);
9 END StudentOps;
10 /
Package created.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY StudentOps AS
2 v_NumHist NUMBER;
3
4 FUNCTION FullName(p_ID IN lecturer.ID%TYPE)
5 RETURN VARCHAR2 IS
6 myResult VARCHAR2(100);
7 BEGIN
8 SELECT first_name || ' ' || last_name
9 INTO myResult
10 FROM lecturer
11 WHERE ID = p_ID;
12
13 RETURN myResult;
14 END FullName;
15
16 FUNCTION NumHistoryMajors RETURN NUMBER IS
17 myResult NUMBER;
18 BEGIN
19 IF v_NumHist IS NULL THEN
20 SELECT COUNT(*)
21 INTO myResult
22 FROM lecturer
23 WHERE major = 'History';
24 v_NumHist := myResult;
25 ELSE
26 myResult := v_NumHist;
27 END IF;
28
29 RETURN myResult;
30 END NumHistoryMajors;
31 END StudentOps;
32 /
Package body created.
SQL>
SQL> drop table lecturer;
Table dropped.
SQL>
SQL>
Related examples in the same category