| How to return row list? (merged) [message #316405] |
Fri, 25 April 2008 00:39  |
hedonist123
Messages: 119 Registered: August 2007
|
Senior Member |
|
|
Hi,
I have a query
select name, deptno from dept.
Output is
John Manufacturing
However, I want the output to be
John 420 Manufacturing
John 445 Manufacturing
John 133 Manufacturing
John 764 Manufacturing
John 845 Manufacturing
John 673 Manufacturing
The Numbers are statuses which I shall return by calling a function.
Now, I want the function to return a record list so that the John and manufacturing get duplicated and my final result set has the same number of records that the function returns.
For this, what datatype should I return from the function and could you please provide me with the syntax?
Thanks,
Sharath
|
|
|
|
|
|
| Re: Can Function return a list? [message #316439 is a reply to message #316409] |
Fri, 25 April 2008 02:31   |
hedonist123
Messages: 119 Registered: August 2007
|
Senior Member |
|
|
Michel,
When I use a cursor, the result set that I get is
John <cursor> Manufacturing.
How can I pass this to the code?
Let me make my requirement a bit more clear
This is my query
SELECT
PARENT,
CHILD,
MIN(SAL)
FROM
PARENTCHILD,
SAL
WHERE
PARENTCHILD.NAME = SAL.NAME
GROUP BY
PARENT
HAVING
MIN(SAL) > 2500;
Now here, the children have salaries and not the parents, I wish to return the minimum of the childrens salary as the salary of the parent.
You can say that I could write it like this
SELECT
PARENT,
MIN(SAL)
FROM
PARENTCHILD,
SAL
WHERE
PARENTCHILD.NAME = SAL.NAME
GROUP BY
PARENT
HAVING
MIN(SAL) > 2500;
However, they wish to see the parent, the minimum salary of the children and their children names too.
So, I wish to return the children's names through a separate function which uses this query
select
child
from
parentchild
where parent = parentvalue;
This will return multiple records.
How do I write a function to return multiple records?
The final record set would be like this
Parent Child Min(sal)
JOHN JESSICA 2560
JOHN JASON 2560
JOHN BRIAN 2560
JOHN MOLLY 2560
DAVE SEAN 2600
DAVE MIKE 2600
Here the minimum salary of Johns Children may be that of jessica, however it should as the same for all of his children
Thanks so much for your time.
Sharath
[Updated on: Fri, 25 April 2008 02:50] Report message to a moderator
|
|
|
|
| How to return row list? [message #316468 is a reply to message #316405] |
Fri, 25 April 2008 04:23   |
hedonist123
Messages: 119 Registered: August 2007
|
Senior Member |
|
|
Hi,
This is my query
SELECT
PARENT,
CHILD,
MIN(SAL)
FROM
PARENTCHILD,
SAL
WHERE
PARENTCHILD.NAME = SAL.NAME
GROUP BY
PARENT
HAVING
MIN(SAL) > 2500;
Here, the children have salaries and not the parents, I wish to return the minimum of the childrens salary as the salary of the parent.
You could say that I could write it like this
SELECT
PARENT,
MIN(SAL)
FROM
PARENTCHILD,
SAL
WHERE
PARENTCHILD.NAME = SAL.NAME
GROUP BY
PARENT
HAVING
MIN(SAL) > 2500;
However, they wish to see the parent, the minimum salary of the children and their children names too.
So, I wish to return the children's names through a separate function which uses this query
select
child
from
parentchild
where parent = parentvalue;
This will return multiple records.
How do I write a function to return multiple records?
The final record set would be like this
Parent Child Min(sal)
JOHN JESSICA 2560
JOHN JASON 2560
JOHN BRIAN 2560
JOHN MOLLY 2560
DAVE SEAN 2600
DAVE MIKE 2600
Here the minimum salary of Johns Children may be that of jessica, however it should as the same for all of his children
Thanks so much for your time.
Sharath
[Updated on: Fri, 25 April 2008 04:25] Report message to a moderator
|
|
|
|
|
|
|
|
|
|