Without RESTRICT_REFERENCES pragma. : Package « PL SQL « Oracle PL / SQL






Without 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
  3    FUNCTION FullName(p_ID IN lecturer.ID%TYPE)
  4      RETURN VARCHAR2;
  5    FUNCTION NumHistoryMajors
  6      RETURN NUMBER;
  7  END StudentOps;
  8  /

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>
SQL> drop table lecturer;

Table dropped.

SQL>

   
    
    
  








Related examples in the same category

1.Create a package declaration and create its body after
2.Create a package level variable
3.call utitilities package
4.Package for output employee table and log message
5.Package with package level cursor variable
6.Overloading Packaged Subprograms
7.A PL/SQL package with two methods
8.Package level Exception
9.This package will not compile because the body does not match the specification.
10.dependencies between an anonymous calling block and package runtime state.
11.RESTRICT_REFERENCES pragma.
12.Persistance of packaged variables.
13.A package with one method
14.Package level variable as global level variable
15.Global definition
16.Student fetch package
17.Cursor operation between package functions
18.The pragma is not valid at the package level.
19.Create package and member cursor
20.Nested package reference
21.Overloaded packages.
22.Overloading based on user defined object types.
23.package RECURSION
24.Crosss reference between two packages
25.Counter package
26.Package initialization.
27.Packages allows forward references, thus opening the possibilities for recursion.
28.Use package level type as global variables
29.Use package member variable to pass value