Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The code listed below creates a package with only a specification. I keep getting an error.

Error:

Error: PL/SQL: Compilation unit analysis terminated
Error(1,14): PLS-00201: identifier 'TAXRATE_PKG' must be declared                        
Error(1,14): PLS-00304: cannot compile body of 'TAXRATE_PKG' without its specification

Code:

CREATE OR REPLACE PACKAGE BODY TAXRATE_PKG IS 

    PROCEDURE state_tax_pf(
                    p_state IN VARCHAR2,
                    pv_tax_nc OUT NUMBER, 
                    pv_tax_tx OUT NUMBER, 
                    pv_tax_tn OUT NUMBER) 
    IS 
        lv_state NUMBER; 
    BEGIN 
       IF p_state = 'NC' THEN 
           pv_tax_nc := 0.35; 
       ELSIF p_state = 'TX' THEN 
           Pv_tax_tx := 0.05; 
       ELSIF p_state = 'TN' THEN 
           pv_tax_tn := 0.02; 
       END IF; 

       RETURN lv_state; 

    END; 
END;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
201 views
Welcome To Ask or Share your Answers For Others

1 Answer

The code listed below creates a package with only a specification

but your code shows that you are creating a package BODY

CREATE OR REPLACE PACKAGE 
    BODY TAXRATE_PKG IS  -- your code doesnt follow what you are trying to do

    PROCEDURE state_tax_pf(
                    p_state IN VARCHAR2,
                    pv_tax_nc OUT NUMBER, 
                    pv_tax_tx OUT NUMBER, 
                    pv_tax_tn OUT NUMBER) 
    IS 
        lv_state NUMBER; 
    BEGIN 
       IF p_state = 'NC' THEN 
           pv_tax_nc := 0.35; 
       ELSIF p_state = 'TX' THEN 
           Pv_tax_tx := 0.05; 
       ELSIF p_state = 'TN' THEN 
           pv_tax_tn := 0.02; 
       END IF; 

       RETURN lv_state; 

    END; 
END;

A PACKAGE SPECIFICATION

  • contains only the first line of your PROCEDURES/FUNCTIONS,

  • It starts with CREATE OR REPLACE PACKAGE and doesnt include the word "BODY" since its the specification and not the BODY of the package.

While a PACKAGE BODY

  • contains the BODY of the procedures/functions starting from the word "PROCEDURE" up to the END statement of the procedure.

If you want to create a package with only specification. You should write it like this:

CREATE OR REPLACE PACKAGE 
     TAXRATE_PKG IS

PROCEDURE state_tax_pf(
                    p_state IN VARCHAR2,
                    pv_tax_nc OUT NUMBER, 
                    pv_tax_tx OUT NUMBER, 
                    pv_tax_tn OUT NUMBER) ;

END TAXRATE_PKG;

Just to warn you, you have a procedure inside but you are returning a value.This will return an error. You should make sure that the codes you are inserting in a package works to avoid having too many errors.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...