dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

Returning result of a simple "select * " from a stored procedure without using cursor - Oracle Server

This is a discussion on Returning result of a simple "select * " from a stored procedure without using cursor - Oracle Server ; Hi All, I am very novice in oracle and I do not know whether I am asking a stupid question. I want to create a stored procedure that returns all the rows from a table say, 'Employee'. The stored procedure ...


Home > Database Forum > Oracle Database > Oracle Server > Returning result of a simple "select * " from a stored procedure without using cursor

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 10-15-2003, 11:25 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Returning result of a simple "select * " from a stored procedure without using cursor

Hi All,

I am very novice in oracle and I do not know whether I am asking a
stupid question.

I want to create a stored procedure that returns all the rows from a
table say, 'Employee'. The stored procedure should return the same
set of rows as a simple statement "select * from Employee" returns.

In SQL Server this can be done as follows

create procedure Test1
as
select * from Employee

How can I do this in Oracle in a similar way? I do not want to use
cursors to do a simple select.

Thanks in advance,
Sreenish
Reply With Quote
  #2  
Old 10-15-2003, 11:49 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Returning result of a simple "select * " from a stored procedurewithout using cursor



Sreenish wrote:

> Hi All,
>
> I am very novice in oracle and I do not know whether I am asking a
> stupid question.
>
> I want to create a stored procedure that returns all the rows from a
> table say, 'Employee'. The stored procedure should return the same
> set of rows as a simple statement "select * from Employee" returns.
>
> In SQL Server this can be done as follows
>
> create procedure Test1
> as
> select * from Employee
>
> How can I do this in Oracle in a similar way? I do not want to use
> cursors to do a simple select.
>
> Thanks in advance,
> Sreenish


Hi, no it's not a stupid question, and the answer is "you can't". Oracle's
procedures cannot return 'inline' results like a simple query. You must
use the non-standard JDBC getting of a result set from output parameters.
Joe Weinstein at BEA


Reply With Quote
  #3  
Old 10-15-2003, 07:41 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Returning result of a simple "select * " from a stored procedure without using cursor

Joseph Weinstein wrote in message news:<3F8D6C8B.3E823BAB@bea.com>...
> Sreenish wrote:
>
> > Hi All,
> >
> > I am very novice in oracle and I do not know whether I am asking a
> > stupid question.
> >
> > I want to create a stored procedure that returns all the rows from a
> > table say, 'Employee'. The stored procedure should return the same
> > set of rows as a simple statement "select * from Employee" returns.
> >
> > In SQL Server this can be done as follows
> >
> > create procedure Test1
> > as
> > select * from Employee
> >
> > How can I do this in Oracle in a similar way? I do not want to use
> > cursors to do a simple select.
> >
> > Thanks in advance,
> > Sreenish

>
> Hi, no it's not a stupid question, and the answer is "you can't". Oracle's
> procedures cannot return 'inline' results like a simple query. You must
> use the non-standard JDBC getting of a result set from output parameters.
> Joe Weinstein at BEA


Sreenish, depending on which version of Oracle you are on and what
your front-end application is there are ways to return a row set from
a procedure. With Oracle 9 you can select from a pipelined procedure
like it was a table. Prior to this you can use such features as
Reference Cursors, object types, and pl/sql tables to accomplish the
task though I am not sure any of these methods meet your simple select
rule.

Look at the following url for a possible solution for both versions 9i
and 8i.
http://asktom.oracle.com/pls/ask/f?=...:2270447621346

HTH -- Mark D Powell --
Reply With Quote
  #4  
Old 10-15-2003, 09:50 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Returning result of a simple "select * " from a stored procedure without using cursor



"Sreenish" wrote in message
news:ab2bce66.0310150724.a6f35bb@posting.google.co m...
> Hi All,
>
> I am very novice in oracle and I do not know whether I am asking a
> stupid question.
>
> I want to create a stored procedure that returns all the rows from a
> table say, 'Employee'. The stored procedure should return the same
> set of rows as a simple statement "select * from Employee" returns.
>
> In SQL Server this can be done as follows
>
> create procedure Test1
> as
> select * from Employee
>
> How can I do this in Oracle in a similar way? I do not want to use
> cursors to do a simple select.
>
> Thanks in advance,
> Sreenish


Use an out parameter and make the parameter a ref cursor. then you just
call the stored proc. See the documentation.
Jim


Reply With Quote
  #5  
Old 10-16-2003, 12:13 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Returning result of a simple "select * " from a stored procedurewithout using cursor



Jim Kennedy wrote:

> "Sreenish" wrote in message
> news:ab2bce66.0310150724.a6f35bb@posting.google.co m...
> > Hi All,
> >
> > I am very novice in oracle and I do not know whether I am asking a
> > stupid question.
> >
> > I want to create a stored procedure that returns all the rows from a
> > table say, 'Employee'. The stored procedure should return the same
> > set of rows as a simple statement "select * from Employee" returns.
> >
> > In SQL Server this can be done as follows
> >
> > create procedure Test1
> > as
> > select * from Employee
> >
> > How can I do this in Oracle in a similar way? I do not want to use
> > cursors to do a simple select.
> >
> > Thanks in advance,
> > Sreenish

>
> Use an out parameter and make the parameter a ref cursor. then you just
> call the stored proc. See the documentation.
> Jim


See the post! ;-) He already said he didn't want to use a cursor. If an oracle procedure
could act exactly like a simple query, then he could stick to standard JDBC, but they
don't so he can't....
Joe


Reply With Quote
  #6  
Old 10-16-2003, 12:21 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Returning result of a simple "select * " from a stored procedure without using cursor


"Joseph Weinstein" wrote in message
news:3F8E1AC0.FE95D9FD@bea.com...
>
>
> Jim Kennedy wrote:
>
> > "Sreenish" wrote in message
> > news:ab2bce66.0310150724.a6f35bb@posting.google.co m...
> > > Hi All,
> > >
> > > I am very novice in oracle and I do not know whether I am asking a
> > > stupid question.
> > >
> > > I want to create a stored procedure that returns all the rows from a
> > > table say, 'Employee'. The stored procedure should return the same
> > > set of rows as a simple statement "select * from Employee" returns.
> > >
> > > In SQL Server this can be done as follows
> > >
> > > create procedure Test1
> > > as
> > > select * from Employee
> > >
> > > How can I do this in Oracle in a similar way? I do not want to use
> > > cursors to do a simple select.
> > >
> > > Thanks in advance,
> > > Sreenish

> >
> > Use an out parameter and make the parameter a ref cursor. then you just
> > call the stored proc. See the documentation.
> > Jim

>
> See the post! ;-) He already said he didn't want to use a cursor. If an

oracle procedure
> could act exactly like a simple query, then he could stick to standard

JDBC, but they
> don't so he can't....
> Joe
>
>

I did read the post. He can use a cursor. He just thinks he can't because
of concurrency problems in sqlServer which you don't have in Oracle. (read
novice Oracle user) It doesn't hurt to read the documentation.
Jim


Reply With Quote
  #7  
Old 10-16-2003, 01:57 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Returning result of a simple "select * " from a stored procedure without using cursor

sreenish@hotmail.com (Sreenish) wrote

> How can I do this in Oracle in a similar way? I do not want to use
> cursors to do a simple select.


As for not wanting to use a cursor. A cursor is by default what is
created on the server as the result of a SELECT and what is used on
the client. Period.

And this applies to SQL-Server as well. Read the dblib API.

Thus, not wanting to use a cursor makes no sense at all. What
requirement are you trying to satisfy by saying that you do not want
to use a cursor?

If you're complaint is that Oracle does not allow the Transact SQL way
of doing things, then think again.

Do not use Oracle wearing a SQL-Server hat. And vice versa.

Oracle is considered the top db platform for *exactly* that reason.
'cause it aint nothing like SQL-Server when you take the hood off.

Products do not sell because of "Me Too!" features. They sell because
they are *different*. Marketing 101.



--
Billy
Reply With Quote
  #8  
Old 10-16-2003, 05:13 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Returning result of a simple "select * " from a stored procedure without using cursor

"Joseph Weinstein" wrote in message
news:3F8E1AC0.FE95D9FD@bea.com...
>
>
> Jim Kennedy wrote:
>
> > "Sreenish" wrote in message
> > news:ab2bce66.0310150724.a6f35bb@posting.google.co m...
> > > Hi All,
> > >
> > > I am very novice in oracle and I do not know whether I am asking a
> > > stupid question.
> > >
> > > I want to create a stored procedure that returns all the rows from a
> > > table say, 'Employee'. The stored procedure should return the same
> > > set of rows as a simple statement "select * from Employee" returns.
> > >
> > > In SQL Server this can be done as follows
> > >
> > > create procedure Test1
> > > as
> > > select * from Employee
> > >
> > > How can I do this in Oracle in a similar way? I do not want to use
> > > cursors to do a simple select.
> > >
> > > Thanks in advance,
> > > Sreenish

> >
> > Use an out parameter and make the parameter a ref cursor. then you just
> > call the stored proc. See the documentation.
> > Jim

>
> See the post! ;-) He already said he didn't want to use a cursor. If an

oracle procedure
> could act exactly like a simple query, then he could stick to standard

JDBC, but they
> don't so he can't....


Couple of things.

1. What has JDBC got to do with it? Given that he is coming to Oracle from
MSSQL I'd be guessing almost any other connectivity technology. Yes he'd
have to use parameters with ADO/ADO.Net as well but really who cares - its
not rocket science after all.

2. That aside, what do you want us to say? No Oracle can't do what you want.
Not the most helpful of answers really is it, when just by dropping a self
imposed restriction you get the exact same functionality. I mean suppose I
said to an mssql group "I want to join two tables in an sql query using the
(+) outer join syntax" "you can't" is not nearly as helpful as "you can't
use that syntax but here is the syntax you should be using".


--
Niall Litchfield
Oracle DBA
Audit Commission UK


Reply With Quote
  #9  
Old 10-16-2003, 11:29 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Returning result of a simple "select * " from a stored procedurewithout using cursor



Jim Kennedy wrote:

> "Joseph Weinstein" wrote in message
> news:3F8E1AC0.FE95D9FD@bea.com...
> >
> >
> > Jim Kennedy wrote:
> >
> > > "Sreenish" wrote in message
> > > news:ab2bce66.0310150724.a6f35bb@posting.google.co m...
> > > > Hi All,
> > > >
> > > > I am very novice in oracle and I do not know whether I am asking a
> > > > stupid question.
> > > >
> > > > I want to create a stored procedure that returns all the rows from a
> > > > table say, 'Employee'. The stored procedure should return the same
> > > > set of rows as a simple statement "select * from Employee" returns.
> > > >
> > > > In SQL Server this can be done as follows
> > > >
> > > > create procedure Test1
> > > > as
> > > > select * from Employee
> > > >
> > > > How can I do this in Oracle in a similar way? I do not want to use
> > > > cursors to do a simple select.
> > > >
> > > > Thanks in advance,
> > > > Sreenish
> > >
> > > Use an out parameter and make the parameter a ref cursor. then you just
> > > call the stored proc. See the documentation.
> > > Jim

> >
> > See the post! ;-) He already said he didn't want to use a cursor. If an

> oracle procedure
> > could act exactly like a simple query, then he could stick to standard

> JDBC, but they
> > don't so he can't....
> > Joe
> >
> >

> I did read the post. He can use a cursor. He just thinks he can't because
> of concurrency problems in sqlServer which you don't have in Oracle. (read
> novice Oracle user) It doesn't hurt to read the documentation.
> Jim


Your powers of interpretation may be better than mine... My assumption is
that he has a standard JDBC application which works now, and he wants it
to work with Oracle too, and it won't. I am not councilling that he abandon
Oracle, but rather to simple know that he will have to do some oracle-specific
coding.
Joe

Reply With Quote
  #10  
Old 10-16-2003, 11:33 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Returning result of a simple "select * " from a stored procedurewithout using cursor



Niall Litchfield wrote:

> "Joseph Weinstein" wrote in message
> news:3F8E1AC0.FE95D9FD@bea.com...
> >
> >
> > Jim Kennedy wrote:
> >
> > > "Sreenish" wrote in message
> > > news:ab2bce66.0310150724.a6f35bb@posting.google.co m...
> > > > Hi All,
> > > >
> > > > I am very novice in oracle and I do not know whether I am asking a
> > > > stupid question.
> > > >
> > > > I want to create a stored procedure that returns all the rows from a
> > > > table say, 'Employee'. The stored procedure should return the same
> > > > set of rows as a simple statement "select * from Employee" returns.
> > > >
> > > > In SQL Server this can be done as follows
> > > >
> > > > create procedure Test1
> > > > as
> > > > select * from Employee
> > > >
> > > > How can I do this in Oracle in a similar way? I do not want to use
> > > > cursors to do a simple select.
> > > >
> > > > Thanks in advance,
> > > > Sreenish
> > >
> > > Use an out parameter and make the parameter a ref cursor. then you just
> > > call the stored proc. See the documentation.
> > > Jim

> >
> > See the post! ;-) He already said he didn't want to use a cursor. If an

> oracle procedure
> > could act exactly like a simple query, then he could stick to standard

> JDBC, but they
> > don't so he can't....

>
> Couple of things.
>
> 1. What has JDBC got to do with it? Given that he is coming to Oracle from
> MSSQL I'd be guessing almost any other connectivity technology. Yes he'd
> have to use parameters with ADO/ADO.Net as well but really who cares - its
> not rocket science after all.


You are correct to ask. I have to admit my absolutely unfounded assumption of
JDBC, simply from my very specialized backround! Mea culpa, you are correct!

> 2. That aside, what do you want us to say? No Oracle can't do what you want.
> Not the most helpful of answers really is it, when just by dropping a self
> imposed restriction you get the exact same functionality. I mean suppose I
> said to an mssql group "I want to join two tables in an sql query using the
> (+) outer join syntax" "you can't" is not nearly as helpful as "you can't
> use that syntax but here is the syntax you should be using".


Agreed, but there may be some gravitas to the self-imposed limitation, such as
"I have a working application, built laboriously to standard APIs, and want it
to work with Oracle (or MS)". It may be the appropriate thing to starkly state
that for the migration they intend, they will either fail, or will have to alter the
application to do some vendor-specific things.
Joe

>
>
> --
> Niall Litchfield
> Oracle DBA
> Audit Commission UK


Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 03:57 AM.