Solved

How to return an OUT parameter from and ORACLE

Posted on 2016-11-15
3
80 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
  • 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

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

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…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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 configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

808 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