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;
but your code shows that you are creating a package BODY
A PACKAGE SPECIFICATION
While a PACKAGE BODY
If you want to create a package with only specification. You should write it like this:
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.
There are some problems with your code. First your error is because you are creating a
PACKAGE
and in Oracle to do so you have to create the specification first. It is like anInterface
inJava
or aHeader
file inC
. So, for your code get rid of that error you have to do:The other problems you have in your code is more like logic problems.
You defined a
procedure
but you are returning a valueRETURN lv_state;
and you didn't even assign any value to it that makes no sense. No need for that return statement or that variable since you are not using it at all.Another problem is you created three
OUT
parameters (unless the code that use this is testing any of that other values for null) that isn't assigned (because of yourif
) you just need one of then lets saypv_tax OUT NUMBER
.The other problem that I see is that if you need that
RETURN lv_state;
for something you have to change yourprocedure
into afunction
and assign that variable to something.Hope it Helps you to understand.