Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to return an OUT parameter from and ORACLE

Posted on 2016-11-15
3
Medium Priority
?
111 Views
Last Modified: 2016-11-16
I need to find out how to return an OUT parameter from an ORACLE stored procedure. Below is a very very small and simple stored procedure with an output parameter named auditFlag.

Somehow I also need to set the value of auditingIndicator based upon the query being executed.

So, how can I set the value of auditingIndicator  based upon the query being executed at line 9? And how do I return the value using
my OUT parameter : auditFlag ?

1 CREATE PROCEDURE PROCESS_TRACKER (
2   tableName IN VARCHAR := NULL,
3   auditFlag IN OUT CHAR)
4 AS
5   queryString VARCHAR2(5000);
6   auditingIndicator INT;

7  BEGIN
8   auditingIndicator := 0;
9   queryString := 'SELECT auditValue FROM ' || tableName || ' WHERE isMarked = 1';
10   EXECUTE IMMEDIATE queryString;
   -- Somehow set "auditingIndicator" based on executing the previous query string
11    IF auditingIndicator = 1
12     THEN
      -- Do something
 13   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
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 1000 total points
ID: 41889235
Hi,

you cannot select without an into clause in the select statement in your execute immediate query. Please correct it.

Assuming that you have corrected this, based on the returned value from the column, you can do the below if condition to assign value to your out variable.

IF auditingIndicator_variable = 1
   THEN
      auditFlag := 'Y';
else
auditFlag := 'N';
 END IF;

Thanks,
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 41889242
also i would suggest addition exception handlers to your code block so you can  trap no data found, too may rows, etc. That would be helpful for you to understand if any errors/issues to easily debug/troubleshoot code.

Thanks,
0
 
LVL 20

Assisted Solution

by:flow01
flow01 earned 1000 total points
ID: 41889497
first follow the posts above
1)
returning the out   parameter

declare
   v_auditFlag  varchar2(10);
begin
   PROCESS_TRACKER ('your table_name',v_auditFlag);
   dbms_output.put_line('The value of the auditFlag:' || v_auditFlag);
end;

2)
if the procedure has only 1 out  parameter   you also can change it to a function
CREATE FUNCTION PROCESS_TRACKER (  tableName IN VARCHAR) RETURN varchar2
IS
  v_auditFlag  varchar2(10);
BEGIN
   ...
   RETURN v_auditFlag;
END;

-- then getting the value gets
begin
      dbms_output.put_line('The value of the auditFlag:' || PROCESS_TRACKER ('your table_name'));
end;

3
a select into  expects only 1 row to be found :  if 2 rows are found you wil get an error
You really get 1 row  when executing  SELECT auditValue FROM  yourtableName  WHERE isMarked = 1?
0

Featured Post

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!

Question has a verified solution.

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

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…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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

715 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