Solved

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

Posted on 2016-11-16
7
29 Views
Last Modified: 2016-11-17
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;
0
Comment
Question by:brgdotnet
  • 3
  • 2
  • 2
7 Comments
 
LVL 34

Accepted Solution

by:
johnsone earned 500 total points
ID: 41890743
Within a stored procedure, the call should be:

GET_AUDIT_FLAG('Customer',returnValue);
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 41890747
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);
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 41890754
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

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 41890755
>> myValue := GET_AUDIT_FLAG('Customer',returnValue);

That would work if get_audit_flag was a function and returned a value.
0
 
LVL 34

Expert Comment

by:johnsone
ID: 41891213
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.
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 41891426
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 :)
0
 
LVL 2

Author Closing Comment

by:brgdotnet
ID: 41892386
Perfect solution. You really helped me. Thank you for posting an accurate example.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now