473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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
Nov 12 '05 #1
20 6454
"Praveen" <sp**********@yahoo.com> wrote in message
news:98**************************@posting.google.c om...
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


Can you tell us what VARRAY does?
Nov 12 '05 #2
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
Nov 12 '05 #3
Mark A wrote:
"Praveen" <sp**********@yahoo.com> wrote in message
news:98**************************@posting.google.c om...
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

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
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
da******@x.washington.edu
(replace 'x' with a 'u' to reply)

Nov 12 '05 #4
> > 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


Sounds like 2nd normal form. Another violation of the relational standard by
Oracle.
Nov 12 '05 #5
Mark A wrote:
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

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


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
da******@x.washington.edu
(replace 'x' with a 'u' to reply)

Nov 12 '05 #6
"Daniel Morgan" <da******@x.washington.edu> wrote in message
news:1075997670.868621@yasure...
Mark A wrote:
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

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


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


Well, at least you admitted that Oracle is not relational. I don't consider
relational to be hammer.
Nov 12 '05 #7
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
Nov 12 '05 #8
Serge Rielau wrote:
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


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

Nov 12 '05 #9
Serge Rielau wrote:
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


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

Nov 12 '05 #10
"Mark Townsend" <ma***********@comcast.net> wrote in message
news:40**************@comcast.net...
Serge Rielau wrote:
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


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

Ok, this second time you double posted. Are you confused about something?
Nov 12 '05 #11
>
Ok, this second time you double posted. Are you confused about something?

You mean your newsgroup server doesn't run on RAC ? Mine does :-) We
also have dual slide projectors as well (seriously)

Nov 12 '05 #12
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 <sr*****@ca.eye-be-em.com> wrote in message news:<bv**********@hanover.torolab.ibm.com>...
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

Nov 12 '05 #13
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
Nov 12 '05 #14
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
Nov 12 '05 #15
AT IOUG that is preaching to the devil? :)

Serge Rielau wrote:
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

--
Anton Versteeg
IBM Certified DB2 Specialist
IBM Netherlands
Nov 12 '05 #16
Which is what missionaries do ;-)

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #17
He's just posting an array of 2 messages... ;-)

PM

"Mark A" <ma@switchboard.net> a écrit dans le message de
news:1D*****************@news.uswest.net...
"Mark Townsend" <ma***********@comcast.net> wrote in message
news:40**************@comcast.net...
Serge Rielau wrote:
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


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

Ok, this second time you double posted. Are you confused about something?

Nov 12 '05 #18
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 <sr*****@ca.eye-be-em.com> wrote in message news:<c0**********@hanover.torolab.ibm.com>...
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

Nov 12 '05 #19
Praveen wrote:
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


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
da******@x.washington.edu
(replace 'x' with a 'u' to reply)

Nov 12 '05 #20
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
Nov 12 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: John | last post by:
Is there an equivalent of COM on Linux that I can get through Python. My need is to have some sort of language independent component framework. I can think of CORBA but I have to have a server...
2
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. ...
3
by: Robert Dodier | last post by:
Hello, Here's a thought that I'm sure has already occurred to someone else, I just can't find any record of it yet. An XML document is just a more verbose and clumsy representation of an...
1
by: Vannela | last post by:
Is there any equivalent control in .NET for the Power builder DataWindow control? I am explaining the Datawindow architecture to some extent. Power Builder DataWindow Control has got different...
0
by: richasaraf | last post by:
Hey Guys !!!! Please help me out....... i have to make a small application using VARRAYS in Oracle 9i.... Can you guys suggest me something good....... Thanks in advance... and hoping for...
7
by: Tim Conner | last post by:
Hi, I am an ex-delphi programmer, and I having a real hard time with the following simple code (example ): Which is the equivalent to the following code ? var chars : PChar; sBack, s :...
10
by: karch | last post by:
How would this C# contruct be represented in C++/CLI? Or is it even possible? PolicyLevel level = (enumerator->Current) as PolicyLevel; Thanks, Karch
9
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric...
14
by: grid | last post by:
Hi, I have a certain situation where a particular piece of code works on a particular compiler but fails on another proprietary compiler.It seems to have been fixed but I just want to confirm if...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.