Solved

Return 2 data values (integer, varchar2) from Oracle stored Function

Posted on 2007-03-28
6
867 Views
Last Modified: 2010-08-05
I'm new developer in Oracle. So please bear if it's too basic question and would appreciate your patience in answering.   My requirement is to get 2 parameter (Integer,varchar2)values back from Oracle Stored Function. Could someone give me an example on how to accomplish this.
      
0
Comment
Question by:vasudev_v
6 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 18809493
A function only supports one return value.  However, a stored procedure supports multiple output parameters.
0
 
LVL 15

Accepted Solution

by:
OMC2000 earned 50 total points
ID: 18809577
You could convert your integer value to string and concatenate it with your string with some seprater character,  '#' for instance, then in caller procedure or function you could extract both values with instr and substr builtin functions
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 18809606
You can return a delimited character string something like:
----------------------
create or replace function myFunc return varchar2
is
      someNumber number := 1;
      someString varchar2(20) := 'some string';
begin
      return to_char(someNumber) || ':' || someString;
end;
/

show errors

select myFunc() from dual;



0
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.

 
LVL 34

Expert Comment

by:johnsone
ID: 18810824
Just to clarify, out parameters are supported in both functions and procedures.

create function test_func (out_var out varchar2) return number as
begin
out_var := 'test';
return(1);
end;
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 18811464
True but you can't use a function with an out parameter as part of a select statement.  You have to use it within PL/SQL itself:
----------------------------
var bob varchar2(100)

-- fails
select test_func(:bob) from dual;

--works
declare
      myString varchar2(10);
      myNumber number;
begin
      myNumber := test_func(myString);
      dbms_output.put_line('String: ' || myString);
      dbms_output.put_line('Number: ' || myNumber);
end;
/
0
 
LVL 34

Expert Comment

by:johnsone
ID: 18815518
Not sure of the original intention for use.  Just wanted to point out that it is possible to use out parameters in a function.  May not be practical in this case.

As a more complex way to return more than one value, a ref cursor is possible and can be used in a select statement.

create or replace package test_pack is
 type rcur is ref cursor;
 function test_func return rcur;
end;
/

create or replace package body test_pack is
 function test_func return rcur is
   return_cursor rcur;
 begin
   open return_cursor for select 1, 'test' from dual;
   return return_cursor;
 end;
end;
/
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

Suggested Solutions

Title # Comments Views Activity
Oracle Database Upgrade 13 62
oracle report printing 2 pages in one page 2 58
Oracle -- identify blocking session 24 43
Read only access to a Procedure in oracle? 4 48
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
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 shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now