Define a RETURN statement

Is it possible to define a RETURN statement in the exception part of a function?
Explain it with example.

Showing Answers 1 - 6 of 6 Answers

Kamal

  • May 23rd, 2015
 

Yes, you can return from exception block.
example: create or replace function TestReturn return varchar2 is
Result varchar2(1);--size 1
begin
Result := 123;--size 3
return Test;

exception when others then
return sqlerrm;
end TestReturn;
---------------------------
declare
test_ varchar2(100);
BEgin
test_ := TestReturn();
dbms_output.put_line(test_);
end;
.above code returns the exception
ORA-06502: PL/SQL: numeric or value error: character string buffer too small

  Was this answer useful?  Yes

Aryan

  • May 26th, 2015
 

Yes it is possible to use Return in exception block of pl/sql.
Example:

Code
  1. CREATE OR REPLACE FUNCTION <function_name> [(input/output variable declarations)] RETURN return_type

  2. [AUTHID <CURRENT_USER | DEFINER>] <IS|AS>   -- heading part

  3. amount NUMBER;   -- declaration block

  4. BEGIN   -- executable part

  5.         <PL/SQL block WITH RETURN statement>

  6.         RETURN <return_value>;

  7. [EXCEPTION

  8.         none]

  9.         RETURN <return_value>;

  10. END;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions