Solved

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

Posted on 2016-11-16
7
63 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 35

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 77

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 77

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 35

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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…

738 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