Solved

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

Posted on 2016-11-16
7
66 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

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.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

707 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