Solved

How to return an OUT parameter from and ORACLE

Posted on 2016-11-15
3
92 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 250 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 250 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

751 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