Unix Technical Forum

Simple Cursor

This is a discussion on Simple Cursor within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Ive been looking online and cant seem to find a good example of a cursor I need to create..I ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 12:40 PM
Jimbo
 
Posts: n/a
Default Simple Cursor

Ive been looking online and cant seem to find a good example of a
cursor I need to create..I want to assign variables in a cursor then
select them in a recordset....its simple to do in sql server..but i
cant seem to find a way in oracle....I dont have permission to create
temp tables and Im not looking to do db outputs...if someone could
provide an example that would be great...


Thanks

-Jim

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 12:40 PM
Frank van Bortel
 
Posts: n/a
Default Re: Simple Cursor

Jimbo schreef:
> Ive been looking online and cant seem to find a good example of a
> cursor I need to create..I want to assign variables in a cursor then
> select them in a recordset....its simple to do in sql server..but i
> cant seem to find a way in oracle....I dont have permission to create
> temp tables and Im not looking to do db outputs...if someone could
> provide an example that would be great...
>
>
> Thanks
>
> -Jim
>

AAARRRRGGHHH!!!

Temp tables, TEMP tables, TEMPTABLES?!?!

A cursor returns a pointer into your recordset, so I fail to
see how you can "assign variables in a cursor" and "then
select them".

what do you want to do - and why use a cursor? Never
use pl/sql when you can do it in SQL.

Why would you:
declare
cursor c_sel_emp IS select * from emp;
l_out varchar2(240);
begin
for r_emp in c_sel_emp
loop
l_out := r_emp.ename;
dbms_output.put_line(l_out);
end loop;
end;

when you can:
select ename from emp;

--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 12:40 PM
Jimbo
 
Posts: n/a
Default Re: Simple Cursor

ok heres what Im trying to do....Im trying to flatten a record
set...so say case number 07 has orders 1 and 3 associated with
it....if you do a select youll get.

case number order number
----------------- --------------------
07 1
07 3

I want to use a cursor so I can concatenate the order number field and
return

case number order numbers order count
------------------ --------------------- -----------------
07 1, 3 2

I can only think to do this with a cursor....if you know another way
Im all ears

-Jim

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 12:40 PM
DA Morgan
 
Posts: n/a
Default Re: Simple Cursor

Jimbo wrote:
> ok heres what Im trying to do....Im trying to flatten a record
> set...so say case number 07 has orders 1 and 3 associated with
> it....if you do a select youll get.
>
> case number order number
> ----------------- --------------------
> 07 1
> 07 3
>
> I want to use a cursor so I can concatenate the order number field and
> return
>
> case number order numbers order count
> ------------------ --------------------- -----------------
> 07 1, 3 2
>
> I can only think to do this with a cursor....if you know another way
> Im all ears
>
> -Jim


Have you heard of cross-tabulation? Pivot tables? Use DECODE.

Example at www.psoug.org
Click on Morgan's Library
Click on DECODE.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-08-2008, 12:40 PM
Frank van Bortel
 
Posts: n/a
Default Re: Simple Cursor

On 27 apr, 00:22, Jimbo <jamesfer...@hotmail.com> wrote:
> ok heres what Im trying to do....Im trying to flatten a record
> set...so say case number 07 has orders 1 and 3 associated with
> it....if you do a select youll get.
>
> case number order number
> ----------------- --------------------
> 07 1
> 07 3
>
> I want to use a cursor so I can concatenate the order number field and
> return
>
> case number order numbers order count
> ------------------ --------------------- -----------------
> 07 1, 3 2
>
> I can only think to do this with a cursor....if you know another way
> Im all ears
>
> -Jim


Why would you want to flatten (denormalize) a record - what's the
bigger picture
behind this - probably you focus on a little piece where te big
picture
can give a completely different (and for Oracle, far more effective!)
solution.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-08-2008, 12:40 PM
Jimbo
 
Posts: n/a
Default Re: Simple Cursor

I found an example of how to do what I was talking about...yes I want
to do a pivot table...and yes a cursor is needed....heres the link...

http://weblogs.asp.net/stevencohn/ar...28/362373.aspx


Thanks for all your help...


-Jim

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:07 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com