user7635140
user7635140

Reputation:

While doing plsql i encountered the following error

create procedure hcf2(a in number,b in number) return number as
begin
   if b = 0 then
     return a;
   else
     return hcf2(b,mod(a,b));
   end if;
end;

Got the Error

LINE/COL ERROR
-------- -----------------------------------------------------------------
1/41     PLS-00103: Encountered the symbol "RETURN" when expecting one of
         the following:
         ; is with authid as cluster order using external
         deterministic parallel_enable pipelined result_cache
         The symbol "authid was inserted before "RETURN" to continue.

Upvotes: 0

Views: 403

Answers (2)

krokodilko
krokodilko

Reputation: 36127

Please read the documentation of RETURN statement

expression

Optional when the RETURN statement is in a pipelined table function. Required when the RETURN statement is in any other function. Not allowed when the RETURN statement is in a procedure or anonymous block.


Since you are trying to create a procedure, then you can't use an expression in the RETURN statement.

Upvotes: 1

Avrajit Roy
Avrajit Roy

Reputation: 3303

Basically what you are trying here is to use a Function rather than Procedure. A RETURN statement can be used in two ways. One in FUNCTION where it determines the return Type of the Functon. And the second type,Oracle server immediately sends the execution control back to the immediate calling code or host environment. No further statements are processed in the block following the RETURN statement.

create or replace function hcf2(a in number,b in number) return number as
begin
   if b = 0 then
     return a;
   else
     return hcf2(b,mod(a,b));
   end if;
end;

Upvotes: 1

Related Questions