Reputation: 9
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:
Upvotes: 1
Views: 835
Reputation: 146219
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.
Upvotes: 3