PLS-00452: Subprogram 'GETNAME' violates its associated pragma : Packages « Function Procedure Packages « Oracle PL/SQL Tutorial






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>








27.10.Packages
27.10.1.Packages
27.10.2.Private Versus Public Package Objects
27.10.3.Package State
27.10.4.Recompiling Packages
27.10.5.All packages can be recompiled by using the Oracle utility dbms_utility:
27.10.6.Creating a Package Specification
27.10.7.Creating a Package Body
27.10.8.Creating Packages and call its functions
27.10.9.Calling Functions and Procedures in a Package
27.10.10.A Package Specification and its body
27.10.11.Overloading Packaged Subprograms
27.10.12.Calls procedure in a package
27.10.13.Dropping a Package
27.10.14.Calling a Cursor Declared in a Different Package
27.10.15.Reference fields and methods in package
27.10.16.Controlling access to packages
27.10.17.Globals Stored in a Package
27.10.18.A Subtypes Example
27.10.19.Generate Random number
27.10.20.Crosss reference between two packages
27.10.21.package RECURSION
27.10.22.Using RESTRICT_REFERENCES in a Package
27.10.23.PLS-00452: Subprogram 'GETNAME' violates its associated pragma
27.10.24.Dynamically create packages