SQL>
SQL>
SQL> create table product(
2 product_id number(4) not null,
3 product_description varchar2(20) not null
4 );
Table created.
SQL>
SQL> insert into product values (1,'Java');
1 row created.
SQL> insert into product values (2,'Oracle');
1 row created.
SQL> insert into product values (3,'C#');
1 row created.
SQL> insert into product values (4,'Javascript');
1 row created.
SQL> insert into product values (5,'Python');
1 row created.
SQL>
SQL>
SQL> create table company(
2 product_id number(4) not null,
3 company_id NUMBER(8) not null,
4 company_short_name varchar2(30) not null,
5 company_long_name varchar2(60)
6 );
Table created.
SQL> insert into company values(1,1001,'A Inc.','Long Name A Inc.');
1 row created.
SQL> insert into company values(1,1002,'B Inc.','Long Name B Inc.');
1 row created.
SQL> insert into company values(1,1003,'C Inc.','Long Name C Inc.');
1 row created.
SQL> insert into company values(2,1004,'D Inc.','Long Name D Inc.');
1 row created.
SQL> insert into company values(2,1005,'E Inc.','Long Name E Inc.');
1 row created.
SQL> insert into company values(2,1006,'F Inc.','Long Name F Inc.');
1 row created.
SQL>
SQL> create table product_company(
2 product_id number(4) not null,
3 product_description varchar2(20) not null,
4 company_id NUMBER(8) not null,
5 company_short_name varchar2(30) not null,
6 company_long_name varchar2(60)
7 );
Table created.
SQL>
SQL>
SQL>
SQL> CREATE OR REPLACE PACKAGE myPackage
2 IS
3 FUNCTION getName(ip_product_id NUMBER,ip_company_id NUMBER)
4 RETURN VARCHAR2;
5 PRAGMA RESTRICT_REFERENCES(getName,WNDS,WNPS);
6 END myPackage;
7 /
Package created.
SQL>
SQL> show errors
No errors.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY myPackage
2 IS
3 FUNCTION getName(ip_product_id NUMBER,ip_company_id NUMBER)
4 RETURN VARCHAR2
5 IS
6 v_name VARCHAR2(120);
7 v_product_description VARCHAR2(20);
8 v_company_short_name VARCHAR2(30);
9 v_company_long_name VARCHAR2(60);
10 BEGIN
11 SELECT 'Org Name: (Short) '||company_short_name||' (Long) '||company_long_name
12 INTO v_name
13 FROM company
14 WHERE product_id = ip_product_id
15 AND company_id = ip_company_id;
16 SELECT product_description
17 INTO v_product_description
18 FROM product
19 WHERE product_id = ip_product_id;
20 SELECT company_short_name,company_long_name
21 INTO v_company_short_name,v_company_long_name
22 FROM company
23 WHERE product_id = ip_product_id
24 AND company_id = ip_company_id;
25 INSERT INTO product_company VALUES
26 (ip_product_id,v_product_description,ip_company_id,
27 v_company_short_name,v_company_long_name);
28 RETURN (v_name);
29 END getName;
30 END myPackage;
31 /
Warning: Package Body created with compilation errors.
SQL> show errors
Errors for PACKAGE BODY MYPACKAGE:
LINE/COL
--------
ERROR
-----------------------------------------------------------------
3/3
PLS-00452: Subprogram 'GETNAME' violates its associated pragma
SQL>
SQL>
SQL> drop table company;
Table dropped.
SQL>
SQL> drop table product;
Table dropped.
SQL>
SQL> drop table product_company;
Table dropped.
SQL>
|