
November 12th, 2005, 06:28 AM
| | | 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 | 
November 12th, 2005, 06:28 AM
| | | 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? | 
November 12th, 2005, 06:28 AM
| | | 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 | 
November 12th, 2005, 06:28 AM
| | | 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. | 
November 12th, 2005, 06:28 AM
| | | 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) | 
November 12th, 2005, 06:28 AM
| | | 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. | 
November 12th, 2005, 06:28 AM
| | | 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 | 
November 12th, 2005, 06:29 AM
| | | 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 ? | 
November 12th, 2005, 06:29 AM
| | | 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 ? | 
November 12th, 2005, 06:29 AM
| | | 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? | 
November 12th, 2005, 06:29 AM
| | | 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) | 
November 12th, 2005, 06:29 AM
| | | 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] | 
November 12th, 2005, 06:29 AM
| | | 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 | 
November 12th, 2005, 06:29 AM
| | | 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 | 
November 12th, 2005, 06:30 AM
| | | 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 | 
November 12th, 2005, 06:30 AM
| | | Re: Equivalent of VARRAYs in DB2
Which is what missionaries do ;-)
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab | 
November 12th, 2005, 06:30 AM
| | | 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] | 
November 12th, 2005, 06:30 AM
| | | 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] | 
November 12th, 2005, 06:30 AM
| | | 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) | 
November 12th, 2005, 06:31 AM
| | | 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 | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | 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.
|