Create or replace PROCEDURE SSp_EmpHoursInfo
(p_EHrsInfo OUT SYS_REFCURSOR)
AS
BEGIN
OPEN p_EHrsInfo FOR
Select
a.personid, a.first_name, a.last_name,c.hoursworked,d.carecentername, c.break
from person a
join employee b on a.personid = b.empersonid
join employee_assigned_care_center c on b.empersonid = c.empersonid
join care_center d on c.empersonid = d.carecenterid
where hoursworked> 10;
END SSp_EmpHoursInfo;
Everytime I am trying to call the store procedure it is giving me this error msg:
Error starting at line : 225 in command -
BEGIN SSp_EmpHoursInfo (hoursworked> 10); END;
Error report -
ORA-06550: line 1, column 3:
PLS-00201: identifier 'HOURSWORKED' must be declared
ORA-06550: line 1, column 52:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
The problem is very obvious.
BEGIN SSp_EmpHoursInfo (hoursworked> 10); END; is not the proper way of calling it.
The procedure parameter must be the sys_refcursor.
You must use:
DECLARE
OUTPUT_CUR SYS_REFCURSOR;
BEGIN
SSp_EmpHoursInfo (OUTPUT_CUR );
-- USE CURSOR ACCORDINGLY
END;
/
CREATE OR REPLACE TRIGGER trg_test
AFTER DELETE
ON ADMİN.KULLANICILAR
for each row
DECLARE
v_username := USER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_username);
END;
Hey guys I'm getting that error always I put every privalege to my user and
it says :
after editing
CREATE OR REPLACE TRIGGER trg_test
AFTER DELETE
ON ADMİN.KULLANICILAR
for each row
DECLARE
v_username nvarchar2(20) := USER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_username);
END;
and error like that it ll runs on apex but not on oracle sql dev:
BEGIN
DBMS_OUTPUT.PUT_LINE(v_username);
END;
Error report -
ORA-06550: line 2, column 26:
PLS-00201: identifier 'V_USERNAME' must be declared
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
I have two schemas SCHEMA_1 and SCHEMA_2.
In SCHEMA_1, I have 2 tables, LOCATIONS and COUNCILS, with the following structure:
CREATE TABLE SCHEMA_1.COUNCILS
( ID NUMBER(*,0),
DCOUNCIL VARCHAR2(200 BYTE),
CONSTRAINT COUNCILS_PK PRIMARY KEY ("ID")
);
CREATE TABLE SCHEMA_1.LOCATIONS
( ID NUMBER(*,0),
DLOCATION VARCHAR2(200 BYTE),
COUNCIL_ID NUMBER(*,0),
CONSTRAINT LOCATIONS_PK PRIMARY KEY ("ID"),
CONSTRAINT LOCATIONS_R01 FOREIGN KEY ("COUNCIL_ID")
REFERENCES SCHEMA_1.COUNCILS ("ID") ENABLE
);
I also have, in SCHEMA_1, compiled one package, which includes a function to select the denomination of all locations inside a council:
CREATE OR REPLACE PACKAGE SCHEMA_1.PAQ_LOCATIONS
IS
TYPE t_TABLE_LOCATIONS IS TABLE OF LOCATIONS%ROWTYPE
INDEX BY BINARY_INTEGER;
FUNCTION OBTAIN_ALL
(
pe_council_id IN COUNCILS.ID%TYPE
)
RETURN t_TABLE_LOCATIONS;
END PAQ_LOCATIONS;
CREATE OR REPLACE PACKAGE BODY SCHEMA_1.PAQ_LOCATIONS
IS
FUNCTION OBTAIN_ALL
(
pe_council_id IN COUNCILS.ID%TYPE
)
RETURN t_TABLE_LOCATIONS
IS
CURSOR cur_locations
IS
SELECT *
FROM LOCATIONS
WHERE COUNCIL_ID = pe_council_id;
v_tlocations t_TABLE_LOCATIONS;
v_counter BINARY_INTEGER;
BEGIN
v_counter := 0;
FOR reg_location IN cur_locations
LOOP
v_contador := v_counter + 1;
v_tlocations ( v_counter ) := reg_location;
END LOOP;
RETURN v_tlocations;
END OBTAIN_ALL;
END PAQ_LOCATIONS;
Then, I have granted execution privileges on "PAQ_LOCATIONS" to "SCHEMA_2".
PRIVILEGE GRANTEE GRANTABLE GRANTOR OBJECT_NAME
EXECUTE SCHEMA_2 NO SCHEMA_1 PAQ_LOCATIONS
In "ESQUEMA_2", I try to execute "PAQ_LOCATIONS":
DECLARE
v_locations SCHEMA_1.PAQ_LOCATIONS.t_TABLE_LOCATIONS;
BEGIN
v_locations := SCHEMA_1.PAQ_LOCATIONS.OBTAIN_ALL ( 6015 );
FOR i IN v_locations.FIRST .. v_locations.LAST
LOOP
DBMS_OUTPUT.put_line ( v_locations (i).DLOCATION );
END LOOP;
END;
Then it throws an exception:
"
Error que empieza en la línea: 1 del comando :
DECLARE
...etc...
END;
ORA-06550: línea 2, columna 27:
PLS-00201: identifier 'SCHEMA_1.PAQ_LOCATIONS' must be declared
ORA-06550: línea 2, columna 27:
PL/SQL: Item ignored
ORA-06550: línea 5, columna 8:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: línea 5, columna 8:
PL/SQL: Statement ignored
ORA-06550: línea 7, columna 22:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: línea 7, columna 8:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
"
logged as the user CC_LOPES I have this procedure:
create or replace PACKAGE BODY "P_MSG_HOTEL" AS
function parse_msg(p_id in number, p_msg in varchar2) return number is
...
end;
That I try to execute from Oracle SQL Developer with
EXECUTE P_MSG_HOTEL.parse_msg(596210657, '#S,358639058787154;E,10;D,05102017145210,05102017145210;G,4046393,51206983,258,8;M,4709;S,0;IO,1,0,0;DI,79DEAD60');
I got this error:
Error que empieza en la línea: 1 del comando :
BEGIN P_MSG_HOTEL.parse_msg(596210657, '#S,358639058787154;E,10;D,05102017145210,05102017145210;G,4046393,51206983,258,8;M,4709;S,0;IO,1,0,0;DI,79DEAD60'); END;
Informe de error -
ORA-06550: línea 1, columna 126:
PLS-00306: wrong number or types of arguments in call to 'PARSE_MSG'
ORA-06550: línea 1, columna 126:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Am really excited to know incase you really got the error you mentioned in your question.
Ideally you must had got something like:
*
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00221: 'PARSE_MSG' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
But you posted :
Error que empieza en la línea: 1 del comando :
BEGIN P_MSG_HOTEL.parse_msg(596210657, '#S,358639058787154;E,10;D,05102017145210,05102017145210;G,4046393,51206983,258,8;M,4709;S,0;IO,1,0,0;DI,79DEAD60'); END;
Informe de error -
ORA-06550: línea 1, columna 126:
PLS-00306: wrong number or types of arguments in call to 'PARSE_MSG'
ORA-06550: línea 1, columna 126:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
This looks quiet misleading.
I did the below demo to show what i meant.
CREATE OR REPLACE PACKAGE P_MSG_HOTEL
AS
FUNCTION parse_msg (p_id IN NUMBER, p_msg IN VARCHAR2)
RETURN NUMBER;
END;
/
CREATE OR REPLACE PACKAGE BODY P_MSG_HOTEL
AS
FUNCTION parse_msg (p_id IN NUMBER, p_msg IN VARCHAR2)
RETURN NUMBER
IS
BEGIN
RETURN 1;
END;
END;
On execution the way you showed it gives the error which say :
EXECUTE P_MSG_HOTEL.parse_msg(596210657,
'#S,358639058787154;E,10;D,05102017145210,05102017145210;G,4046393,51206983,258,8;M,4709;S,0;IO,1,0,0;DI,79DEAD60');
Error
*
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00221: 'PARSE_MSG' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
This clearly means Oracle is not able to identify your function while execution.
However when i do like:
SQL>
select P_MSG_HOTEL.parse_msg(596210657, '#S,358639058787154;E,10;D,05102017145210,05102017145210;G,4046393,51206983,258,8;M,4709;S,0;IO,1,0,0;DI,79DEAD60') as col
from dualSQL> 2
3 /
COL
----------
1
I get the output.
Or if i use an Anonymous block i get the result.
SQL> DECLARE
x NUMBER;
BEGIN
x :=
P_MSG_HOTEL.parse_msg (
596210657,
'#S,358639058787154;E,10;D,05102017145210,05102017145210;G,4046393,51206983,258,8;M,4709;S,0;IO,1,0,0;DI,79DEAD60');
2 DBMS_OUTPUT.put_line (x);
END;
/
1
PL/SQL procedure successfully completed.
SQL>
So, in short, you cannot use the function the way you are executing.
Don't execute the function directly . either do it inside DBMS_OUTPUT
SET SERVEROUTPUT ON
EXEC DBMS_OUTPUT.PUT_LINE(P_MSG_HOTEL.parse_msg(arg1,arg2));
Or run a query with function in select to get the output.
select P_MSG_HOTEL.parse_msg(arg1,arg2) FROM DUAL;
You cannot use execute command to execute a function, the function return some value that needs to be captured somewhere, Use anonymous block:
declare
f_return number;
begin
f_return := P_MSG_HOTEL.parse_msg(596210657, '#S,358639058787154;E,10;D,05102017145210,05102017145210;G,4046393,51206983,258,8;M,4709;S,0;IO,1,0,0;DI,79DEAD60');
end;
/
Using Oracle SQL Developer I created a simple procedure. The procedure compiles successfully, but when I type the command:
execute CMPPROJECTPROCSELECT();
BEGIN CMPPROJECTPROCSELECT(); END;
I get the following errors:
Error starting at line : 1 in command -
execute CMPPROJECTPROCSELECT()
Error report -
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'CMPPROJECTPROCSELECT'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Error starting at line : 2 in command -
BEGIN CMPPROJECTPROCSELECT(); END;
Error report -
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'CMPPROJECTPROCSELECT'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Please help me to solve this. I know it's a small error. Also I have specified the data types, declarations of names correctly.
My procedure code is
CREATE OR REPLACE PROCEDURE CMPPROJECTPROCSELECT(
p_projectname IN VARCHAR2,
p_description OUT VARCHAR2)
IS
BEGIN
SELECT DESCRIPTION
INTO p_description
FROM CMPPROJECT
WHERE PROJECTNAME = p_projectname;
EXCEPTION
WHEN NO_DATA_FOUND THEN
p_description:= NULL;
COMMIT;
END CMPPROJECTPROCSELECT;
execute CMPPROJECTPROCSELECT();
BEGIN CMPPROJECTPROCSELECT();
END;
EXECUTE is SQL*Plus command.
You are not passing the required parameters to the procedure. You have declared two parameters for your procedure:
p_projectname IN VARCHAR2,
p_description OUT VARCHAR2
So, you need to declare the required parameters and then pass it to the procedure:
DECLARE
proj_desc VARCHAR2(2000);
BEGIN
CMPPROJECTPROCSELECT('project_name', proj_desc);
-- use the OUT value of proj_desc later
END;
/
On a side note, you do not need COMMIT at all. It is required to permanently commit a DML and has nothing to do with a SELECT ..INTO clause.
SELECT DESCRIPTION INTO p_description FROM CMPPROJECT WHERE PROJECTNAME = p_projectname;
EXCEPTION
WHEN NO_DATA_FOUND THEN
p_description:= NULL;
COMMIT; -- You don't need COMMIT at all
UPDATE A working demonstration:
In PL/SQL:
SQL> CREATE OR REPLACE PROCEDURE get_emp(
2 p_ename IN VARCHAR2,
3 p_job OUT VARCHAR2)
4 IS
5 BEGIN
6 SELECT job INTO p_job FROM emp WHERE ename = p_ename;
7 END;
8 /
Procedure created.
SQL> sho err
No errors.
SQL> set serveroutput on
SQL> DECLARE
2 job VARCHAR2(20);
3 BEGIN
4 get_emp('SCOTT',JOB);
5 DBMS_OUTPUT.PUT_LINE('The output is '||job);
6 END;
7 /
The output is ANALYST
PL/SQL procedure successfully completed.
In SQL*Plus:
SQL> VARIABLE JOB VARCHAR2(20);
SQL> EXECUTE get_emp('SCOTT', :JOB);
PL/SQL procedure successfully completed.
SQL> PRINT JOB;
JOB
--------------------------------
ANALYST