Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 06:28 AM
Praveen
Guest
 
Posts: n/a
Default Equivalent of VARRAYs in DB2

Hi All,

I have an application for that we used oracle 8i as the db and we have
written procedures using VARRAYs. Now, the requirement came to migrate
it on DB2 UDB. Can anyone pls tell me is there any equivalent or
alternative to VARRAYs in DB2?

Thanks in advance,
Praveen
  #2  
Old November 12th, 2005, 06:28 AM
Mark A
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

"Praveen" <spraveen2001@yahoo.com> wrote in message
news:98d8ec76.0402050528.59351e57@posting.google.c om...[color=blue]
> Hi All,
>
> I have an application for that we used oracle 8i as the db and we have
> written procedures using VARRAYs. Now, the requirement came to migrate
> it on DB2 UDB. Can anyone pls tell me is there any equivalent or
> alternative to VARRAYs in DB2?
>
> Thanks in advance,
> Praveen[/color]

Can you tell us what VARRAY does?


  #3  
Old November 12th, 2005, 06:28 AM
Serge Rielau
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

You can use global temporary tables with NOT LOGGED ON COMMIT RETAIN
ROWS option. If the array is not too big you will end up with one page
pinned in the bufferpool. So it's going to be I/O free.
If you are doing a smart migration this performs very well (with smart I
mean you migrate the function and not line by line (emulation)).
Ideally you want to turn loops over the array into selects and seached
updates.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
  #4  
Old November 12th, 2005, 06:28 AM
Daniel Morgan
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Mark A wrote:[color=blue]
> "Praveen" <spraveen2001@yahoo.com> wrote in message
> news:98d8ec76.0402050528.59351e57@posting.google.c om...
>[color=green]
>>Hi All,
>>
>>I have an application for that we used oracle 8i as the db and we have
>>written procedures using VARRAYs. Now, the requirement came to migrate
>>it on DB2 UDB. Can anyone pls tell me is there any equivalent or
>>alternative to VARRAYs in DB2?
>>
>>Thanks in advance,
>>Praveen[/color]
>
>
> Can you tell us what VARRAY does?[/color]

A user defined data type corresponding to a variable length array.

http://www.psoug.org/reference/varray.html

--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)

  #5  
Old November 12th, 2005, 06:28 AM
Mark A
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

> > Can you tell us what VARRAY does?[color=blue]
>
> A user defined data type corresponding to a variable length array.
>
> http://www.psoug.org/reference/varray.html
>
> --
> Daniel Morgan[/color]

Sounds like 2nd normal form. Another violation of the relational standard by
Oracle.


  #6  
Old November 12th, 2005, 06:28 AM
Daniel Morgan
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Mark A wrote:
[color=blue][color=green][color=darkred]
>>>Can you tell us what VARRAY does?[/color]
>>
>>A user defined data type corresponding to a variable length array.
>>
>>http://www.psoug.org/reference/varray.html
>>
>>--
>>Daniel Morgan[/color]
>
>
> Sounds like 2nd normal form. Another violation of the relational standard by
> Oracle.[/color]

Oracle is not a pure relational database. Rather it is object-relational
and has been since, IIRC version 8.0 many years ago. VARRAYs are used
when creating object tables, object views, and working with their data.

Just because you have a hammer in your toolbox doesn't mean you have to
use it.

--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)

  #7  
Old November 12th, 2005, 06:28 AM
Mark A
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

"Daniel Morgan" <damorgan@x.washington.edu> wrote in message
news:1075997670.868621@yasure...[color=blue]
> Mark A wrote:
>[color=green][color=darkred]
> >>>Can you tell us what VARRAY does?
> >>
> >>A user defined data type corresponding to a variable length array.
> >>
> >>http://www.psoug.org/reference/varray.html
> >>
> >>--
> >>Daniel Morgan[/color]
> >
> >
> > Sounds like 2nd normal form. Another violation of the relational[/color][/color]
standard by[color=blue][color=green]
> > Oracle.[/color]
>
> Oracle is not a pure relational database. Rather it is object-relational
> and has been since, IIRC version 8.0 many years ago. VARRAYs are used
> when creating object tables, object views, and working with their data.
>
> Just because you have a hammer in your toolbox doesn't mean you have to
> use it.
>
> --
> Daniel Morgan[/color]

Well, at least you admitted that Oracle is not relational. I don't consider
relational to be hammer.


  #8  
Old November 12th, 2005, 06:28 AM
Serge Rielau
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Actually I'm in with Daniel for a change (hear, hear).
He was referring to VARRAY as a hammer, btw.
While I would not push arrays in persistent objects like tables, the
procedural(!) part of the DBMS offering which includes in DB2 SQL PL can
benefit from arrays. I'd rather bite my tongue than yell at Oracle for
having arrays, well knowing that they may loom over my head at least as
local variables and routine arguments in some future.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
  #9  
Old November 12th, 2005, 06:29 AM
Mark Townsend
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Serge Rielau wrote:[color=blue]
> Actually I'm in with Daniel for a change (hear, hear).
> He was referring to VARRAY as a hammer, btw.
> While I would not push arrays in persistent objects like tables, the
> procedural(!) part of the DBMS offering which includes in DB2 SQL PL can
> benefit from arrays. I'd rather bite my tongue than yell at Oracle for
> having arrays, well knowing that they may loom over my head at least as
> local variables and routine arguments in some future.
>
> Cheers
> Serge[/color]

Thank you, I was hoping you would comment on this. That's at least 1
beer I owe you - IOUG this year ?

  #10  
Old November 12th, 2005, 06:29 AM
Mark Townsend
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Serge Rielau wrote:[color=blue]
> Actually I'm in with Daniel for a change (hear, hear).
> He was referring to VARRAY as a hammer, btw.
> While I would not push arrays in persistent objects like tables, the
> procedural(!) part of the DBMS offering which includes in DB2 SQL PL can
> benefit from arrays. I'd rather bite my tongue than yell at Oracle for
> having arrays, well knowing that they may loom over my head at least as
> local variables and routine arguments in some future.
>
> Cheers
> Serge[/color]

Thank you, I was hoping you would comment on this. That's at least 1
beer I owe you - IOUG this year ?

  #11  
Old November 12th, 2005, 06:29 AM
Mark A
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

"Mark Townsend" <markbtownsend@comcast.net> wrote in message
news:40230356.3080502@comcast.net...[color=blue]
> Serge Rielau wrote:[color=green]
> > Actually I'm in with Daniel for a change (hear, hear).
> > He was referring to VARRAY as a hammer, btw.
> > While I would not push arrays in persistent objects like tables, the
> > procedural(!) part of the DBMS offering which includes in DB2 SQL PL can
> > benefit from arrays. I'd rather bite my tongue than yell at Oracle for
> > having arrays, well knowing that they may loom over my head at least as
> > local variables and routine arguments in some future.
> >
> > Cheers
> > Serge[/color]
>
> Thank you, I was hoping you would comment on this. That's at least 1
> beer I owe you - IOUG this year ?
>[/color]
Ok, this second time you double posted. Are you confused about something?


  #12  
Old November 12th, 2005, 06:29 AM
Mark Townsend
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

>[color=blue]
> Ok, this second time you double posted. Are you confused about something?
>
>[/color]
You mean your newsgroup server doesn't run on RAC ? Mine does :-) We
also have dual slide projectors as well (seriously)

  #13  
Old November 12th, 2005, 06:29 AM
Praveen
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Hi Serge,

Thanks for your time..
We have used VARRAYs as a parameters in our procedures. So, is there
any equivalent in DB2?

Thanks
praveen

Serge Rielau <srielau@ca.eye-be-em.com> wrote in message news:<bvth5m$a8f$1@hanover.torolab.ibm.com>...[color=blue]
> You can use global temporary tables with NOT LOGGED ON COMMIT RETAIN
> ROWS option. If the array is not too big you will end up with one page
> pinned in the bufferpool. So it's going to be I/O free.
> If you are doing a smart migration this performs very well (with smart I
> mean you migrate the function and not line by line (emulation)).
> Ideally you want to turn loops over the array into selects and seached
> updates.
>
> Cheers
> Serge[/color]
  #14  
Old November 12th, 2005, 06:29 AM
Serge Rielau
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

You're welcome. I'd love to come to IOUG since IDUG keeps rejecting my
submissions. I plan to talk about Oracle -> DB2 migrations this year.
At IDUG that's preaching too the choir.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
  #15  
Old November 12th, 2005, 06:29 AM
Serge Rielau
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

No. If you use c-procedures or UDF, you could simply cast the array to a
base dataype (like a varchar for bit data) and undo it in the body.
In SQL PL you have two choices:
Global temp tables or wrapping the array in another datatype.
The SET and read would best be handled with unfenced c-udf in the later
case.
How big are your arrays? Are they arrays of rows, base datatypes, which,
and are they variable size or fixed?

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
  #16  
Old November 12th, 2005, 06:30 AM
Anton Versteeg
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

AT IOUG that is preaching to the devil? :)

Serge Rielau wrote:
[color=blue]
> You're welcome. I'd love to come to IOUG since IDUG keeps rejecting my
> submissions. I plan to talk about Oracle -> DB2 migrations this year.
> At IDUG that's preaching too the choir.
>
> Cheers
> Serge[/color]


--
Anton Versteeg
IBM Certified DB2 Specialist
IBM Netherlands


  #17  
Old November 12th, 2005, 06:30 AM
Serge Rielau
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Which is what missionaries do ;-)

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
  #18  
Old November 12th, 2005, 06:30 AM
PM \(pm3iinc-nospam\)
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

He's just posting an array of 2 messages... ;-)

PM

"Mark A" <ma@switchboard.net> a écrit dans le message de
news:1DDUb.129$7M6.71665@news.uswest.net...[color=blue]
> "Mark Townsend" <markbtownsend@comcast.net> wrote in message
> news:40230356.3080502@comcast.net...[color=green]
> > Serge Rielau wrote:[color=darkred]
> > > Actually I'm in with Daniel for a change (hear, hear).
> > > He was referring to VARRAY as a hammer, btw.
> > > While I would not push arrays in persistent objects like tables, the
> > > procedural(!) part of the DBMS offering which includes in DB2 SQL PL[/color][/color][/color]
can[color=blue][color=green][color=darkred]
> > > benefit from arrays. I'd rather bite my tongue than yell at Oracle for
> > > having arrays, well knowing that they may loom over my head at least[/color][/color][/color]
as[color=blue][color=green][color=darkred]
> > > local variables and routine arguments in some future.
> > >
> > > Cheers
> > > Serge[/color]
> >
> > Thank you, I was hoping you would comment on this. That's at least 1
> > beer I owe you - IOUG this year ?
> >[/color]
> Ok, this second time you double posted. Are you confused about something?
>
>[/color]


  #19  
Old November 12th, 2005, 06:30 AM
Praveen
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Serge,

We are using arrays of size 100 of type varchar(100). Each varray
contains arround 50 elements(string). Each row one element.

create or replace type v_loc_array is varray(100) of varchar2(100);

Serge, I didn't get about "In SQL PL you have two choices:" in your
response, Can u please give me samll example?

Thanks,
Praveen



Serge Rielau <srielau@ca.eye-be-em.com> wrote in message news:<c00592$qpj$1@hanover.torolab.ibm.com>...[color=blue]
> No. If you use c-procedures or UDF, you could simply cast the array to a
> base dataype (like a varchar for bit data) and undo it in the body.
> In SQL PL you have two choices:
> Global temp tables or wrapping the array in another datatype.
> The SET and read would best be handled with unfenced c-udf in the later
> case.
> How big are your arrays? Are they arrays of rows, base datatypes, which,
> and are they variable size or fixed?
>
> Cheers
> Serge[/color]
  #20  
Old November 12th, 2005, 06:30 AM
Daniel Morgan
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Praveen wrote:
[color=blue]
> Serge,
>
> We are using arrays of size 100 of type varchar(100). Each varray
> contains arround 50 elements(string). Each row one element.
>
> create or replace type v_loc_array is varray(100) of varchar2(100);
>
> Serge, I didn't get about "In SQL PL you have two choices:" in your
> response, Can u please give me samll example?
>
> Thanks,
> Praveen[/color]

I didn't get Serge's advice either. It didn't seem to relate to either
Oracle or answer your question about how to solve the problem now that
you are in DB2.

I suspect from the reaction to Oracle's object features you may need to
recode this as a parent-child relationship using two independent tables
with a referential integrity constraint.

--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)

  #21  
Old November 12th, 2005, 06:31 AM
Serge Rielau
Guest
 
Posts: n/a
Default Re: Equivalent of VARRAYs in DB2

Let me explain:
Option one (I'm not 100% sure on the excact syntax):
DECLARE GLOBAL TEMPORARY TABLE v_loc_array
(idx SMALLINT NOT NULL,
val VARCHAR(100)) NOT LOGGED ON COMMIT PRESERVE ROWS;
INSERT INTO SESSION.v_loc_array(idx) WITH rec AS (recursive query to
produce as many rows as you wish) SELECT rec.idx FROM rec;

If you do not require to access by index then you can scratch the idx
column. In this case usually a lot of procedural goo simply goes away.

Then
UPDATE SESSION.V_LOC_ARRAY SET val = 'Hello' WHERE idx = 5;

Start of with that, then stare at it and rewrite obvious like combining
loops.

Option 2 (I woudl prefer C:
CREATE DISTINCT TYPE v_loc_array AS VARCHAR(11000) FOR BIT DATA
WITH COMPARISONS;
CREATE FUNCTION set(this v_loc_array, idx SMALLINT, val VARCHAR(100))
RETURNS v_loc_array
LANGUAGE C
UNFENCED -- after thorough testing and talkking to your DBA
....

CREATE FUNCTION get(this v_loc_array, idx SMALLINT)
RETURNS VARCHAR(100)
LANGUAGE C
.....

-- Not sure when UDT support was introduced.. may need to fallback
-- to VARCHAR FOR BIT DATA here depending on your version.
-- Cosmetic anyway.
CREATE PROCEDURE p1(INOUT myarray v_loc_array)
....

SET val = GET(myarray, 5);
SET myarray = SET(myarray, 5, 'Hello');


This is what you might call a "black box structured datatype".
I.e. DB2 has no clue it's dealing with an array.

Option 2 is a lot prettier to look at, but requires some C skills
Option 1 _can_ give you big benefits for optimization if you are willing
to do some optimization while porting.

On teh bright side for Option 2: You can publich on developerWorks (or
DevX) and get good money for a couple of C routines with a page of
instructions and the next posetr will not have to redo your efforts :-)

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.