Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

Getting a return value from an IN OUT parameter in Oracle?

How do I get a return value from calling a stored procedure using Oracle sql? I have a stored procedure named "GET_AUDIT_FLAG",
and I want to call it from within another stored procedure. Can soneone show me the Syntax I would need at line 1 in order to get the
return value from my stored procedure "GET_AUDIT_FLAG"? I know my syntax at line 1 is incorrect. Please take into consideration that
I have an IN OUT parameter in the stored procedure GET_AUDIT_FLAG : pocoTableAudited IN OUT CHAR

-- Sql within calling stored procedure.
1.   returnValue := EXECUTE IMMEDIATE GET_AUDIT_FLAG 'Customer'

-- Stored procedure which I want to call
CREATE OR REPLACE
PROCEDURE "GET_AUDIT_FLAG"
  (
      inTableName IN VARCHAR := NULL,
        pocoTableAudited IN OUT CHAR
  )
AS
   lvcSqlString VARCHAR2(2000);
   lnAuditInd INT;
   lvcSQLParm VARCHAR2(100);
BEGIN
    lnAuditInd := 0;
    lvcSqlString := 'SELECT AD_FLAG FROM ' || 'AD_TABLE' || ' WHERE TBTB_NAME = ' || '''' || inTableName || ''''
    EXECUTE IMMEDIATE lvcSqlString INTO lnAuditInd;
    IF lnAuditInd = 1 THEN
          pocoTableAudited := 'Y';
    ELSE
         pocoTableAudited := 'N';
    END IF;
END;
ASKER CERTIFIED SOLUTION
Avatar of johnsone
johnsone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brgdotnet

ASKER

Thanks johnsone. Is that all I need to do? Or do I need to set it to a variable
like this :

 myValue := GET_AUDIT_FLAG('Customer',returnValue);
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

How is this different from your previous question?

https://www.experts-exchange.com/questions/28983337/How-to-return-an-OUT-parameter-from-and-ORACLE.html

You need a variable and you use that in the procedure call.

Here is a quick example using sqlplus or similar tool:
create or replace procedure proc1(p_out out varchar2)
is
begin
	p_out := 'Hello';
end;
/

show errors


create or replace procedure proc2
is
	myoutput varchar2(100);
begin
	proc1(myoutput);
	dbms_output.put_line(myoutput);
end;
/

show errors

exec proc2;

Open in new window

>> myValue := GET_AUDIT_FLAG('Customer',returnValue);

That would work if get_audit_flag was a function and returned a value.
What I posted is what you would use in a procedure.  It is not a function, so it does not return a value so no assignment is necessary and in fact should result in an error.
Thanks Johnsone, I will try out your solution soon. It sounds like you are 100% accurate. Slightvw the previous question was about how to get the value to be returned WITHIN the stored pricedure. My current question is how to get that value when calling the procedure. It looks like Johnsone nailed the solution :)
Perfect solution. You really helped me. Thank you for posting an accurate example.