Solved

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

Posted on 2016-11-16
7
52 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
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…

770 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