I'm learning PL/SQL. When I try to create a function, it doesn't matter regardless of content I get errors. This is the function I wrote as an example:
CREATE OR REPLACE FUNCTION f_sum(num1 NUMBER, num2 NUMBER)
RETURN NUMBER
IS
res NUMBER :=0;
BEGIN
res:= num1 + num2;
RETURN res;
END;
/
This is the error message:
Functıon F_SUM created.
Error starting at line : 5 in command -
BEGIN
res:= num1 + num2;
RETURN res;
END;
Error report -
ORA-06550: line 2, column 5:
PLS-00201: identifier 'RES' must be declared
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored
ORA-06550: line 3, column 5:
PLS-00372: In a procedure, RETURN statement cannot contain an expression
ORA-06550: line 3, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
After running the script, function is created as follows:
create or replace FUNCTION f_sum(num1 NUMBER, num2 NUMBER)
RETURN NUMBER
IS
res NUMBER :=0
Then I try to correct function manually. It works fine when I do this but I don't think this way is correct. For your information I tried pressing F5 and ctrl+enter but none of them seems to be working properly.
Function seems to be OK and it works as expected:
This error line:
suggests you executed only this part of code (SQL*Plus illustration):
which results in error you got:
Basically, it says that procedure's
returnshould be just that:return;.The question is: did you, by any chance, "select" (mark) only that piece of code while executing it? If so, don't select anything.