can function return multiple rows [message #178908] |
Fri, 23 June 2006 06:37 |
ankitvermamca
Messages: 4 Registered: June 2006
|
Junior Member |
|
|
hi,
can i have a pl/sql function that can return multiple rows
may be the syntax will be like
create or replace function multiple() returns ...
begin
select candidateid from tbl_candidateinfo;
..code to return the result of above statement to calling
program..
end;
and functions will be called as
select candidateid from .. where candidateid in( select multiple());
thanks in advance,
ankit
|
|
|
Re: can function return multiple rows [message #178914 is a reply to message #178908] |
Fri, 23 June 2006 07:02 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
Simply replace num_tab with a type of your choice, change the code in the package body, and you're go for launch.
SQL> CREATE OR REPLACE type num_tab is table of number;
2 /
Type created.
SQL> create or replace package pipeline as
2 function get_num_row return num_tab pipelined;
3 end;
4 /
Package created.
SQL> create or replace package body pipeline as
2
3 function get_num_row return num_tab PIPELINED is
4 begin
5 for i in 1 .. 5 loop
6 pipe row ( i );
7 end loop;
8 return;
9 end get_num_row;
10 end;
11 /
Package body created.
SQL>
SQL>
SQL> select * from table(pipeline.get_num_row);
COLUMN_VALUE
------------
1
2
3
4
5
|
|
|
|
|
Re: can function return multiple rows [message #178925 is a reply to message #178914] |
Fri, 23 June 2006 07:29 |
ankitvermamca
Messages: 4 Registered: June 2006
|
Junior Member |
|
|
Mysql support pl/sql to certain extent(It doesnot support intersect, except and minus for example). but it does provide facility to create functions and procedures
we are inclined to develop software using freeware products.So we are not using oracle
Regards,
Ankit
|
|
|
|
|
Re: can function return multiple rows [message #179079 is a reply to message #178932] |
Sat, 24 June 2006 18:51 |
William Robertson
Messages: 1643 Registered: August 2003 Location: London, UK
|
Senior Member |
|
|
From a quick look on the web, it seems this is an example of the MySQL stored procedure language, whatever it's called:
CREATE PROCEDURE curdemo()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE a CHAR(16);
DECLARE b,c INT;
DECLARE cur1 CURSOR FOR SELECT id,data FROM test.t1;
DECLARE cur2 CURSOR FOR SELECT i FROM test.t2;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
OPEN cur1;
OPEN cur2;
REPEAT
FETCH cur1 INTO a, b;
FETCH cur2 INTO c;
IF NOT done THEN
IF b < c THEN
INSERT INTO test.t3 VALUES (a,b);
ELSE
INSERT INTO test.t3 VALUES (a,c);
END IF;
END IF;
UNTIL done END REPEAT;
CLOSE cur1;
CLOSE cur2;
END
While it may have some superficial similarities with PL/SQL, it is clearly not the same language, and I could see no claim to provide Oracle compatibility (which Postgres and Fyracle attempt, for example) so I don't see any evidence at all that "Mysql support pl/sql to certain extent".
Quote: | we are inclined to develop software using freeware products.So we are not using oracle
|
So why not use the Oracle freeware product?
|
|
|
|
|
Re: can function return multiple rows [message #217230 is a reply to message #217184] |
Thu, 01 February 2007 04:39 |
William Robertson
Messages: 1643 Registered: August 2003 Location: London, UK
|
Senior Member |
|
|
victoryhendry wrote on Thu, 01 February 2007 01:01 | Simply we use out and inout parameter Function can return the values ..... in Oracle 9i and 10g.
|
Or any other Oracle version since PL/SQL was first released.
However, the OP wanted to use this in SQL queries.
|
|
|
|
|
Re: can function return multiple rows [message #449181 is a reply to message #178908] |
Sat, 27 March 2010 11:35 |
|
Kevin Meade
Messages: 2103 Registered: December 1999 Location: Connecticut USA
|
Senior Member |
|
|
There are three basic ways to return multiple rows:
1) use a refcursor as the return type
2) use an object table as the return type
3) use a mulit-delimited string as a return type (clob most likely)
Each has advantages and detractors. If you do not know about one of more of these remember: GOOGLE IS YOUR FRIEND.
Kevin
|
|
|