I'm trying to create very basic function to learn.
CREATE OR REPLACE FUNCTION AddNumbers (
num1 NUMBER,
num2 NUMBER
) RETURN NUMBER
IS
result NUMBER;
BEGIN
result := num1 + num2;
RETURN result;
END;
But this function wasn't compiling properly. Here is the error:
Error starting at line : 7 in command - BEGIN result := num1 + num2; RETURN result; END; Error report - ORA-06550: line 2, column 5: PLS-00201: identifier 'RESULT' 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:
When I try to create a function, I always encounter this ORA-06550 error.
There's nothing wrong with code you posted, but I presume that you don't use SQL Developer properly. That error looks as if you selected executable part of function and ... well, executed it:
Don't select anything; just press CTRL + ENTER to create function (or 2nd button in toolbar, named "Execute script"; or press F5). Once you create it, then use it, e.g.
Additional note: PL/SQL code should be terminated with a slash character. If you don't do that and try to run that SELECT (without selecting it), you'll get another error ("PLS-00103: Encountered the symbol "SELECT" ").
Demo:
SQL Developer screenshot: