GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 155 of 168    Print  
Handle Multiple Rows Without Loops
How can we handle multiple rows without using loops in PL SQL?


  
Total Answers and Comments: 2 Last Update: August 18, 2009     Asked by: jaalioracle 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: rajivgupta780184
 
If we want to return multiple row from a function then we can use ref cursor function .Example is given below:

create or replace function f1 return sys_refcursor as
r1 sys_refcursor;
begin open r1 for select * from emp;
return(r1);
end;

call the function as :
select f1 from dual; then it returns :

CURSOR STATEMENT : 1CURSOR STATEMENT : 1 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 10000 10



Above answer was rated as good by the following members:
dbandhanadham
October 31, 2008 05:46:19   
rajivgupta780184 Member Since: August 2008   Contribution: 32    

RE: Handle Multiple Rows Without Loops
If we want to return multiple row from a function then we can use ref cursor
function .Example is given below:

create or replace function f1 return sys_refcursor as
r1 sys_refcursor;
begin open r1 for select * from emp;
return(r1);
end;

call the
function as :
select f1 from
dual;
then it returns :

CURSOR STATEMENT : 1CURSOR STATEMENT : 1 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 10000 10


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
August 18, 2009 06:52:49   
sen_sam86 Member Since: June 2008   Contribution: 10    

RE: Handle Multiple Rows Without Loops
This can be done by a function called TABLE FUNCTION
by means of this you can return more number of rows and columns this is more effective than using ref cursor

regards
sen-prakash

 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : Yes you can pass the whole select statement of the cursor dynamicaly, see ref_cursors.There is also a system package sys.dbms_sql which allows everything to make dynamically. ...
Read Answers (5) | Asked by : sweety

How to return multiple records from procedure?e. g. I fired a select query and I want to retun a result to ?

Hi,We have to select some rows from a table using many conditions in the where clause. Then we have to write those selected rows to one flat file. I know that we can use UTL_FILE package to do this. Is there any better approach to do this??
Read Answers (5) | Asked by : Ritesh

Hi 1.What is difference between procedure and function?1. procedure may or may not return values whereas function must return value2. we can call the function in the sql statements whereas we can't call the procedureExcept these two, is there any difference between these two.2. What is pl/sql table and what is use of it. In which case, we can use it3. What is ref cursor, what is the use of it.4.how the function will return multiple values. Pls give me with examples

Latest Answer : A nested loop is a loop within a lop, an inner loop within the body of an outer one. How this workds is that the first pass of the outer loop triggers the innter which executes to completion. Then the second pass of the outer loop triggers the loop again. ...
Read Answers (1) | Asked by : SAGAR

Hi,1. Iam looking for sample program for ref cursor. ref cursor can be associated with many select statements and we can use the ref cursor to return the multiple value from the procedure or function. 
Latest Answer : Hi,Let me answer your second questin first. Why ref cursor instead of %ROWTYPE.%ROWTYPE is used for fetches record/row of a single table.OR in case of columns of different tables then you have to create a RECORD and then used %ROWTYPE.But ...

How to write a query or procedure or function to retrieve all the tables from database where the table dont have any data (no rows).
Database has 100 tables and some of the tables dont have any data. I want to pullout those table names from database in Oracle. 
Read Answers (3) | Asked by : Robert

Latest Answer : Declare the collection variable (varrys or PL/SQL tables) as out parameter for the procedure and fetch the result set into collection variable. ...

How to return more than one row through functions? Explain with example. 
Latest Answer : create or replace function f1 return sys_refcursor as r1 sys_refcursor; begin open r1 for select * from emp; return(r1); end; call the function as: select f1 from dual; Thanks & Regards RAJIV GUPTA (ORACLE CONSULTANT) YOGIK TECHNOLOGIES ...

How can we handle multiple rows without using loops in PL SQL? 
Latest Answer : This can be done by a function called TABLE FUNCTION by means of this you can return more number of rows and columns this is more effective than using ref cursorregards sen-prakash ...


 Sponsored Links

 
Related Articles

ODP.NET - Retrieving Multiple Rows on to the Grid

ODP NET Retrieving Multiple Rows on to the Grid In the previous section we tried to retrieve only one row using OracleDataReader In this section we will try to retrieve more than one row or a result set and populate a DataGridView on a WinForm mosgoogle The following code lists out the details of al
 

jQuery Expanding and Collapsing Table Rows

jQuery Expanding and Collapsing Table Rows The expanding and collapsing behavior added earlier also conflicts with our filters If a section is collapsed and a new filter is chosen then the matching items are displayed even if in the collapsed section Conversely if the table is filtered and a section
 

jQuery Collapsing and Expanding Table Rows

jQuery Collapsing and Expanding Table Rows When large sets of data are grouped in tables as each year s set of articles are in our News page collapsing or hiding a section s contents can be a convenient way to get a broad view of all of the table s data without having to scroll so much mosgoogle To
 

Multiple Virtual Storage (MVS)

Multiple Virtual Storage MVS First let us start with an insight to the topic Multiple Virtual Storage MVS stands for Multiple Virtual Storage and this is the technology used mainly with IBM mainframe systems MVS origin is interesting to know The first developed technology was MVT which stands for Mu
 

PHP Tutorials - Loops

PHP Tutorials Loops In this PHP Tutorial you will learn about Loops while loop do while loop and the  for loop along with syntax and sample PHP loop codes mosgoogle while loop A while statement executes a code block until a condition is set Example php x 3; Category
 

How To Lead In An Environment With Multiple Cultures

How To Lead In An Environment With Multiple Cultures If you wish to be the leader of a large group you will need to learn how lead people who come from cultural backgrounds which are different from your own Few modern companies can survive by working with people of one cultural group mosgoogle We li
 

Oracle Apps 11i: Internationalization Support and Multiple Reporting Currencies

This tutorial explains about Languages and Character Sets on the Database Tier Languages and Character Sets on the Application Tier Character Sets on the Desktop Tier as part of the Internationalization Support and Multiple Reporting Currencies feature in Oracle Applications 11i Internationalization
 

How to Handle Job Burnout

How to Handle Job Burnout Getting burned-out on the job is not a good thing. Although you can still work as expected your emotional state with regards to work will be very unstable. You can easily get stressed irritable and could be a lot frustrated because of your work conditions. This does not re
 

Tutorial 5: Working with Multiple Tables

This week we will learn Working with multiple Tables which covers Joins Inner Join; Using Table Aliases; Outer Join; Self Join; Non Equi Join Subqueries Simple Subqueries; Multilevel Subqueries; Correlated Subqueries; Predicates Set Operators Set Operator Examples mosgoogle Aliases An alias
 

ODP.NET - Retrieving Multiple Rows on to the Grid

ODP.NET - Retrieving Multiple Rows on to the Grid In the previous section we tried to retrieve only one row using OracleDataReader. In this section we will try to retrieve more than one row or a result set and populate a DataGridView on a WinForm. mosgoogle The following code lists out the details o
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape