I don't understand what is the problem in my store procedure - oracle

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;
/

Related

'LANG_CUR' is not a procedure or is undefined ORA-06550 Error

1.I have been trying to fetch 1 column from a table using reference cursor in plsql, table only has 11 column lang_cur is the declared cursor.
create or replace PACKAGE MOVIE_PKG
AS
PROCEDURE lang_display(lang_cur out SYS_REFCURSOR);
END MOVIE_PKG;
create or replace PACKAGE BODY MOVIE_PKG
AS
PROCEDURE lang_display(lang_cur out SYS_REFCURSOR)
as
begin
OPEN lang_cur FOR select lang_name from LANGUAGE_SELECT;
end lang_display;
END MOVIE_PKG;
declare
lang_cur SYS_REFCURSOR;
begin
movie_pkg.lang_display(lang_cur);
for data in lang_cur
loop
dbms_output.put_line('langauge:'||data.lang_name);
end loop;
end;
GETTING THIS ERROR
ORA-06550: line 5, column 13:
PLS-00221: 'LANG_CUR' is not a procedure or is undefined
ORA-06550: line 5, column 1:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:)```
You can use FETCH:
declare
lang_cur SYS_REFCURSOR;
lang_name LANGUAGE_SELECT.LANG_NAME%TYPE;
begin
movie_pkg.lang_display(lang_cur);
LOOP
FETCH lang_cur INTO lang_name;
EXIT WHEN lang_cur%NOTFOUND;
dbms_output.put_line('langauge:'||lang_name);
END LOOP;
CLOSE lang_cur;
END;
/
db<>fiddle here

X is not a legal cursor attribute plsql

I am trying to find the gcd of two numbers using a recursive approach.
My function:
create or replace function gcd(a in number, b in number)
return number
as
begin
if a = 0
then return b;
else return gcd(b % a, a);
end if;
end;
/
I am calling it like this
declare
a1 number;
b1 number;
z number;
begin
a1:=25;
b1:=40;
z := gcd(a1,b1);
dbms_output.put_line(z);
end;
It throws me this error:
Error report -
ORA-06550: line 15, column 14:
PLS-00208: identifier 'X' is not a legal cursor attribute
ORA-06550: line 15, column 4: PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
b % a is not valid Oracle syntax. If you want to calculate a modulus you need to use the Oracle MOD() function, that is mod(b, a).
You get the PLS-00208 error because Oracle uses the % symbol to reference cursor attributes like %rowtype or %notfound. Find out more.

PLS-00201 Error Occured for the Trigger must be declared pls-00201

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:

PL/SQL compilation error with declaring variable

I am trying to create a basic PL/SQL query where I am using a certain SKU as a parameter so that I can reference it without typing in the sku each time.
When compiling my code I get the error:
Error report:
ORA-06550: line 6, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Here is my code:
declare
myitem number (20);
begin
myitem := 1000956;
select f.order_no
from fdt_maptool f
where f.item = myitem;
end;
/
I thought that maybe it had to do with me using VARCHAR(20) instead of NUMBER, So I tried that as well.
declare
myitem number;
begin
myitem := 1000956;
select f.order_no
from fdt_maptool f
where f.item = myitem;
end;
/
And then received this error:
Error report:
ORA-06550: line 6, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
I am fairly new to PL/SQL so if please go easy on me!
Within PLSQL you need to select into
declare
myitem number(20);
myorder number(20);
begin
myitem := 1000956;
select f.order_no
into myorder
from fdt_maptool f
where f.item = myitem;
end;
/
Now there's two standard things that might go wrong. You may not find a record or you may find more than one record. You need exception handlers to handle these cases.
declare
myitem number(20);
myorder number(20);
begin
myitem := 1000956;
select f.order_no
into myorder
from fdt_maptool f
where f.item = myitem;
exception
when no_data_found then
dbms_output.put_line('No record with this ID');
-- Only needed when not selecting a unique column.
when too_many_rows then
dbms_output.put_line('More than one record with this ID');
end;
/
Note that the too_many_rows exception is usually already covered by the fact that you are selecting an ID column that has a unique constraint defined on it.

wrong number or types of arguments calling a procedure from Oracle SQL Developer

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;
/

Resources