Working on overloaded package throws "Failed to resolve object details" - oracle

I am working on an overloaded package and was wondering 2 things.
1) Is there a way to get more info on what error occurred, like what line number it occurred on, as Failed to resolve object details seams a bit vague.
2) What appears to be wrong with this statement?
CREATE OR REPLACE PACKAGE shop_query_pkg IS
procedure shop_info
(p_id IN bb_shopper.idshopper%TYPE,
p_firstname out bb_shopper.firstname%TYPE);
procedure shop_info
(p_id IN bb_shopper.lastname%TYPE,
p_firstname out bb_shopper.firstname%TYPE);
END;
/
CREATE OR REPLACE PACKAGE BODY show_query_pkg IS
procedure shop_info
(p_id IN bb_shopper.idshopper%TYPE,
p_firstname out bb_shopper.firstname%TYPE);
IS
BEGIN
SELECT firstname
into p_firstname
FROM bb_shopper
WHERE idshopper = p_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('ID does not exist');
END;
-- second procedure
procedure shop_info
(p_id IN bb_shopper.lastname%TYPE,
p_firstname out bb_shopper.firstname%TYPE);
IS
BEGIN
SELECT firstname
into p_firstname
FROM bb_shopper
WHERE lastname = p_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Last name does not exist');
END;
END;
/
show errors;
The error
PACKAGE shop_query_pkg compiled
PACKAGE BODY show_query_pkg compiled
Warning: execution completed with warning
Failed to resolve object details

you cannot use the same name and same number of parameters of same type in the overloaded procedure
and also there the package body name is wrong
and other little mistakes are there
Additionally the first and second procedure
the parameter p_firstname types p_firstname out bb_shopper.firstname%TYPE and bb_shopper.firstname%TYPE are both of type Characters(EITHER BOTH CHAR or BOTH VARCHAR2 etc)
and hence doesn't count as different types
Please use the below
CREATE OR REPLACE PACKAGE shop_query_pkg IS
procedure shop_info(p_id1 IN bb_shopper.idshopper%TYPE,
p_firstname1 out bb_shopper.firstname%TYPE);
procedure shop_info(p_id2 IN bb_shopper.lastname%TYPE,
p_firstname2 out bb_shopper.firstname%TYPE);
END;
/
CREATE OR REPLACE PACKAGE BODY shop_query_pkg IS
procedure shop_info(p_id1 IN bb_shopper.idshopper%TYPE,
p_firstname1 out bb_shopper.firstname%TYPE)
IS
BEGIN
SELECT firstname into p_firstname1 FROM bb_shopper WHERE idshopper = p_id1;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.PUT_LINE('ID does not exist');
END; -- second procedure
procedure shop_info(p_id2 IN bb_shopper.lastname%TYPE,
p_firstname2 out bb_shopper.firstname%TYPE)
IS
BEGIN
SELECT firstname into p_firstname2 FROM bb_shopper WHERE lastname = p_id2;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.PUT_LINE('Last name does not exist');
END;
END;
/
show errors;

Create a package in different schema from APPS and do not create synonym in APPS.
If the package is having some error while compiling, if you are trying to view the error message using 'show error' it will show message as 'Failed to resolve object details' because the package or synonym is not available in APPS schema.

Check to see if the package spec of the package which you are trying to compile is valid of not. I would suggest you to compile the package spec once again and then compile the package body. This has resolved the issue for me.

Related

Error PLS-00103 when create package with Oracle

I'm trying create package with oracle, although I have read many examples in docs oracle and built code same this tutorial but I still error this.
The following code:
create table manage_emplyee
(
f_name varchar(20),
l_name varchar(20)
);
// Specification
create or replace package fn2
as
procedure manage_emplyee(v_fname in VARCHAR2, v_lname in VARCHAR2);
procedure manage_emplyee_delete(v_fname in VARCHAR2);
end;
/
create or replace package body fn2
as
--Procedure Implementation
procedure manage_emplyee(v_fname in VARCHAR2, v_lname in VARCHAR2)
is
begin
insert into manage_emplyee VALUES (v_lname, v_lname);
end manage_emplyee;
// body
procedure manage_emplyee_delete (v_fname in VARCHAR2)
is
begin
delete manage_emplyee where v_fname = v_fname;
end manage_emplyee_delete;
end fn2;
/
Error
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin end function pragma procedure
Please help me fix it, thanks so much !
There are many things incorrect, so here is a correct version.
Run the table script first -
create table manage_emplyee
(
f_name varchar(20),
l_name varchar(20)
);
Run the Spec script after that
create or replace package fn2
as
procedure manage_emplyee(v_fname VARCHAR2,
v_lname VARCHAR2);
procedure manage_emplyee_delete(v_fname VARCHAR2);
end;
/
Run the body script after that
create or replace package body fn2
as
procedure manage_emplyee(v_fname VARCHAR2, v_lname VARCHAR2)
is
begin
insert into manage_emplyee VALUES (v_lname, v_lname);
end ;
procedure manage_emplyee_delete (v_fname VARCHAR2)
is
begin
delete from manage_emplyee where f_name = v_fname;
end ;
end;
/
The syntax for delete from table_name was incorrect.
I am sure, you want to match f_name from table with v_fname from the input variable to delete the data. Earlier you were matching v_fname with v_fname in your code, which will always be true (except for when its passed NULL) and you would end up loosing all your test data
*NOTE -
Adding IN explicitly is not required, the default type is IN for parameters in PLSQL procedures

How to run a complete package in oracle

create or replace package first_pckg IS
PROCEDURE print_name;
FUNCTION ret_eid return number;
END;
create or replace PACKAGE BODY FIRST_PCKG IS
ename employees.first_name%type;
eid employees.employee_id%type;
PROCEDURE print_name is
BEGIN
select first_name into ename from employees where employee_id=100;
dbms_output.put_line(ename);
END;
Function ret_eid return number is
BEGIN
select department_id into eid from employees where employee_id=100;
return eid;
END;
END;
We can execute procedures and functions in packages using execute first_pckg.print_name
can someone let me know how to execute entire package once?
Thank you
A package declares types, functions and procedures: It basically represents a repository of definitions and code. 'Executing' a package does not make much sense in general.
However, packages come with optional initialisation code which will be executed the first time a symbol from the package is referenced during a db session. In your example:
create or replace package first_pckg IS
PROCEDURE print_name;
-- ...
Function ret_eid return number is
BEGIN
select department_id into eid from employees where employee_id=100;
return eid;
END;
BEGIN
-- package init code goes here ...
END package;

Oracle PL/SQL Developer: Return %RowType from Package Procedure

i'm kind of new to Oracle Pl\SQL. I was just trying to create a simple Package with a procedure that returns a set of object id's; the code is as follows:
--Package Spec
CREATE OR REPLACE PACKAGE TEST IS
--GET OBJECT ID'S FROM CONTROL TABLE
PROCEDURE get_object_id_control(p_obj_id OUT abc_table%ROWTYPE);
END;
--Package Body
PROCEDURE get_object_id_control(p_obj_id OUT abc_table%ROWTYPE) AS
BEGIN
SELECT object_id
INTO p_obj_id
FROM abc_table
WHERE fec_proc IS NULL;
END;
I get Error: PL/SQL: ORA-00913: too many values. Is this the correct way for returning multiple values of same data type, or is there a better approach. Thanks in advance.
You can create a custom table type and set the out parameter of the procedure to that type.
CREATE TABLE ABC_TABLE(ID varchar2(100));
create or replace type abc_tab is table of varchar2(100);
/
CREATE OR REPLACE PACKAGE TEST IS
PROCEDURE get_object_id_control(p_obj_id OUT abc_tab);
END;
/
CREATE OR REPLACE PACKAGE BODY TEST IS
PROCEDURE get_object_id_control(p_obj_id OUT abc_tab) AS
BEGIN
SELECT id
bulk collect INTO p_obj_id
FROM abc_table;
END;
END;
/
Then you can call it like so:
declare
v abc_tab;
begin
TEST.get_object_id_control(p_obj_id => v);
for i in v.first..v.last loop
dbms_output.put_line(v(i));
end loop;
end;
/
Similar to GurV's answer (since he beat me by like 30 seconds...), you can use a PL/SQL object type as well. You do not need the CREATE TYPE statement if you don't need to reference the type in SQL.
--Package Spec
CREATE OR REPLACE PACKAGE TEST AS
TYPE id_table_type IS TABLE OF NUMBER;
--GET OBJECT ID'S FROM CONTROL TABLE
PROCEDURE get_object_id_control(p_obj_id_list OUT id_table_type);
END;
--Package Body
CREATE OR REPLACE PACKAGE BODY TEST AS
PROCEDURE get_object_id_control(p_obj_id_list OUT id_table_type) AS
BEGIN
SELECT object_id
BULK COLLECT INTO p_obj_id_list
FROM abc_table
WHERE fec_proc IS NULL;
END;
END;
To use it:
DECLARE
l_id_list test.id_table_type;
BEGIN
test.get_object_id_control (p_obj_id_list => l_id_list);
FOR i IN l_id_list.FIRST .. l_id_list.LAST LOOP
DBMS_OUTPUT.put_line (l_id_list (i));
END LOOP;
END;

Compilation error when creating pl/sql stored procedure

I'm trying to create a stored procedure that used REF CURSOR. I am using this website to find some examples. First I created types:
CREATE OR REPLACE TYPE ROW_TYPE IS OBJECT (
"COL1" CHAR(3 BYTE),
"COL2" NUMBER(4,0)
)
CREATE TYPE ROW_TYPE_TABLE AS TABLE OF ROW_TYPE;
Then created packages:
CREATE OR REPLACE PACKAGE package AS
FUNCTION get_by_id(p_id CHAR) RETURN ROW_TYPE_TABLE PIPELINED;
END package;
But when creating package body using the following command I get the following message PLS-00103: Encountered the symbol "FOR"
I have checked on Oracle official website how to use the open-for statement but can't find my mistake.
CREATE OR REPLACE PACKAGE BODY package AS
FUNCTION get_by_id(p_idCHAR) RETURN SERV_TYPE_TABLE PIPELINED IS
OUT_REC SERV_TYPE_TABLE := SERV_TYPE_TABLE(null,null);
servCursor sys_refcursor;
OPEN servCursor FOR 'SELECT * FROM SERV WHERE COL1= :1' USING p_id;
LOOP
FETCH servCursor INTO OUT_REC.COL1, OUT_REC.COL;
EXIT WHEN servCursor%NOTFOUND;
PIPE ROW(OUT_REC);
END LOOP;
CLOSE servCursor;
RETURN;
END get_by_id;
END package ;
Do you see any problem in the code submitted?
Regards.
PL/SQL functions have the structure:
FUNCTION <function name>(parameter1 <type>, ...) RETURN <return type> IS
<variable declarations>
BEGIN
<function body (code)>
END <function name>;
You forgot the BEGIN.

Successfully compiled Oracle package fails when called with 'ORA-04063: package body "..." has errors

I have a pkg that I use to keep report oriented code CMS_REPORTS.
I added a procedure to return a ref cursor and the pkg compiles fine, but fails when I call the proc to test it with:
ORA-04063: package body "CMS.CMS_REPORTS" has errors
ORA-06508: PL/SQL: could not find program unit being called: "CMS.CMS_REPORTS"
I've removed the orig proc and replaced it with this to keep things simple - same problem.
The proc is this:
procedure test_ref_cur(p_testno in number,
p_cur in out ref_cur) as
begin
open p_cur for
select p_testno + 1 from dual;
end test_ref_cur;
I have defined the ref cursor in the pkg spec like this:
type ref_cur is ref cursor;
procedure test_ref_cur(p_testno in number,
p_cur in out ref_cur);
I've tried all sorts of combinations of using ref cursor and sys_refcursor and all bring up the same error. If I remove the proc from the pkg, it works fine.
I'm beginning to think it's a system issue?
Has anyone else had this problem?
Regards
Dave
Hard to tell what is the issue here, since it doesn't look like we are seeing the relevant code.
So here are some thing I recommend to double check:
package and package body are there and are actually compiled without an exception
you are in the schema/user that contains package and package body.
There are no other objects with the same name, that might hide your package/package body
the procedure you try to call is present in package and package body.
remove all code from package + package body except a single trivial procedure and check if that works.
If you've done all that update the question with the results.
In order to achieve what you want you have to use SYS_REFCURSOR:
create procedure test_ref_cur(p_testno in number,
p_cur in out SYS_REFCURSOR) as
begin
open p_cur for
select p_testno + 1 from dual;
end test_ref_cur;
-- PROCEDURE TEST_REF_CUR compiled
... and example:
DECLARE
l_sysrc SYS_REFCURSOR;
l_num NUMBER;
procedure test_ref_cur(p_testno in number,
p_cur in out SYS_REFCURSOR) as
begin
open p_cur for
select p_testno + 1 from dual;
end test_ref_cur;
BEGIN
test_ref_cur(1, l_sysrc);
FETCH l_sysrc INTO l_num;
DBMS_OUTPUT.PUT_LINE(l_num);
END;
-- Result:
-- 2
Since Oracle 7.3 the REF CURSOR type has been available to allow
recordsets to be returned from stored procedures and functions. Oracle
9i introduced the predefined SYS_REFCURSOR type, meaning we no longer
have to define our own REF CURSOR types.
Source: http://www.oracle-base.com/articles/misc/using-ref-cursors-to-return-recordsets.php

Resources