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

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

Posted on 2007-03-28
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.
Question by:vasudev_v
LVL 42

Expert Comment

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

Accepted Solution

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
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
      someNumber number := 1;
      someString varchar2(20) := 'some string';
      return to_char(someNumber) || ':' || someString;

show errors

select myFunc() from dual;

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

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
out_var := 'test';
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;

      myString varchar2(10);
      myNumber number;
      myNumber := test_func(myString);
      dbms_output.put_line('String: ' || myString);
      dbms_output.put_line('Number: ' || myNumber);
LVL 34

Expert Comment

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;

create or replace package body test_pack is
 function test_func return rcur is
   return_cursor rcur;
   open return_cursor for select 1, 'test' from dual;
   return return_cursor;

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
join 2 views with 5 conditions 3 61
Character matching different date formats for dates between 6 59
ORA-02288: invalid OPEN mode 2 56
add more rows to hierarchy 3 25
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…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to recover a database from a user managed backup

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