Unix Technical Forum

Create a cursor and fill it dynamically

This is a discussion on Create a cursor and fill it dynamically within the DB2 forums, part of the Database Server Software category; --> Hi, It's probably easiest if I describe what I'm trying to do: I have several tables I want to ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 01:50 AM
Wiggy
 
Posts: n/a
Default Create a cursor and fill it dynamically

Hi,

It's probably easiest if I describe what I'm trying to do:

I have several tables I want to base a query on. In addition I have
some dynamic data that I want to join against that consists of several
records of information.

I could just create a temp table of the dynamic data and join it
against my tables, but I thought there was a way to create a cursor
(not based on a table i.e. with a select statement), fill it with the
dynamic data, and join the cursor against the other tables to get my
desired results.

The reason I wanted to do it this was for performance. I'd rather not
incur the hit of writing a temp table to a hard drive, so I thought
the cursor would keep it in memory (of course as long as it doesn't
force memory to get paged out to disk).

I'm not that familiar with DB2. I've read a little about temporary
tables and the temporary global table space. Would using a temp table
be more efficient than my proposal? If so, could you please explain
why? Does the DB not write a temp table to disk if it doesn't need to?

Thanks very much in advance,
William G. Yoder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 01:50 AM
Rhino
 
Posts: n/a
Default Re: Create a cursor and fill it dynamically


"Wiggy" <spambot@yoder.org> wrote in message
news:cd7ef7cf.0410040529.723bc595@posting.google.c om...
> Hi,
>
> It's probably easiest if I describe what I'm trying to do:
>
> I have several tables I want to base a query on. In addition I have
> some dynamic data that I want to join against that consists of several
> records of information.
>
> I could just create a temp table of the dynamic data and join it
> against my tables, but I thought there was a way to create a cursor
> (not based on a table i.e. with a select statement), fill it with the
> dynamic data, and join the cursor against the other tables to get my
> desired results.
>
> The reason I wanted to do it this was for performance. I'd rather not
> incur the hit of writing a temp table to a hard drive, so I thought
> the cursor would keep it in memory (of course as long as it doesn't
> force memory to get paged out to disk).
>
> I'm not that familiar with DB2. I've read a little about temporary
> tables and the temporary global table space. Would using a temp table
> be more efficient than my proposal? If so, could you please explain
> why? Does the DB not write a temp table to disk if it doesn't need to?
>

A table function may be a better solution to your problem. They are capable
of reading data that is not in a DB2 table, such as in a flat file or some
other format. You can then join data found by the table function to other
data from DB2 tables.

I don't recall how table functions handle memory and/or disk space but it
should be in the DB2 manuals somewhere.

Rhino


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 01:50 AM
Gert van der Kooij
 
Posts: n/a
Default Re: Create a cursor and fill it dynamically

In article <cd7ef7cf.0410040529.723bc595@posting.google.com >, Wiggy
(spambot@yoder.org) says...
> Hi,
>
> It's probably easiest if I describe what I'm trying to do:
>
> I have several tables I want to base a query on. In addition I have
> some dynamic data that I want to join against that consists of several
> records of information.
>


Something like this:

WITH temp1 (col1, col2, col3) AS
(VALUES ( 0, ?AA?, 0.00),
( 1, ?BB?, 1.11),
( 2, ?CC?, 2.22)
)

This example is copied from Graeme Birchall's SQL Cookbook which you
can find at
http://ourworld.compuserve.com/homep...l/HTM_COOK.HTM

Hope this helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 01:53 AM
William G. Yoder
 
Posts: n/a
Default Re: Create a cursor and fill it dynamically

Gert & Rhino. Thanks very much for the responses!

spambot@yoder.org (Wiggy) wrote in message news:<cd7ef7cf.0410040529.723bc595@posting.google. com>...
> Hi,
>
> It's probably easiest if I describe what I'm trying to do:
>
> I have several tables I want to base a query on. In addition I have
> some dynamic data that I want to join against that consists of several
> records of information.
>
> I could just create a temp table of the dynamic data and join it
> against my tables, but I thought there was a way to create a cursor
> (not based on a table i.e. with a select statement), fill it with the
> dynamic data, and join the cursor against the other tables to get my
> desired results.
>
> The reason I wanted to do it this was for performance. I'd rather not
> incur the hit of writing a temp table to a hard drive, so I thought
> the cursor would keep it in memory (of course as long as it doesn't
> force memory to get paged out to disk).
>
> I'm not that familiar with DB2. I've read a little about temporary
> tables and the temporary global table space. Would using a temp table
> be more efficient than my proposal? If so, could you please explain
> why? Does the DB not write a temp table to disk if it doesn't need to?
>
> Thanks very much in advance,
> William G. Yoder

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 02:05 AM.


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