473,383 Members | 1,874 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,383 software developers and data experts.

DB2: Oracle equivalent of Autonomus transaction

I have a requirement where I have to generate sequnce like numbers
within another key.

My table is like,

custrec
-------
cust# seq#
10 1
10 2
10 4
10 5

20 1
20 2
20 3
20 4

...
...

For various reasons, I can not use sequnces. In Oracle I have a table
with as the following, which keeps the last sequnce number for each
cust# and autonomous transaction updates the maxseq#.

mastseq:
--------
cust# maxseq#
------ -------
10 5
20 4

Is there any way, I can get the same thing done in DB2.

Note, I do not want to select the maxseq# with "for update of", as
this will hold the lock until the transaction is complete. Also, I can
not commit the record immediately after updating the maxseq# within
the cust#, as this means inconsistent transaction.

Any Alternatives are welcome.

thanks,
Nov 12 '05 #1
6 3635

"Prince Kumar" <gs**@yahoo.com> wrote in message
news:62**************************@posting.google.c om...
I have a requirement where I have to generate sequnce like numbers
within another key.

My table is like,

custrec
-------
cust# seq#
10 1
10 2
10 4
10 5

20 1
20 2
20 3
20 4

..
..

For various reasons, I can not use sequnces. In Oracle I have a table
with as the following, which keeps the last sequnce number for each
cust# and autonomous transaction updates the maxseq#.

mastseq:
--------
cust# maxseq#
------ -------
10 5
20 4

Is there any way, I can get the same thing done in DB2.

Note, I do not want to select the maxseq# with "for update of", as
this will hold the lock until the transaction is complete. Also, I can
not commit the record immediately after updating the maxseq# within
the cust#, as this means inconsistent transaction.

Any Alternatives are welcome.

thanks,


The lock held (SIX) with "for update of" will not lock out others who are
only doing selects. It will only lock others who are doing "for update of"
on the same row (and of course for direct updates of the data).

The actual exclusive lock (X) takes place when the "update where current of
cursor..." is issued. As long as you commit soon after that, you should be
OK.
Nov 12 '05 #2
Can you use generate_unique() (note - this will not generate keys in
sequence) or IDENTITY?

Prince Kumar wrote:
I have a requirement where I have to generate sequnce like numbers
within another key.

My table is like,

custrec
-------
cust# seq#
10 1
10 2
10 4
10 5

20 1
20 2
20 3
20 4

..
..

For various reasons, I can not use sequnces. In Oracle I have a table
with as the following, which keeps the last sequnce number for each
cust# and autonomous transaction updates the maxseq#.

mastseq:
--------
cust# maxseq#
------ -------
10 5
20 4

Is there any way, I can get the same thing done in DB2.

Note, I do not want to select the maxseq# with "for update of", as
this will hold the lock until the transaction is complete. Also, I can
not commit the record immediately after updating the maxseq# within
the cust#, as this means inconsistent transaction.

Any Alternatives are welcome.

thanks,


Nov 12 '05 #3
Can you post the pseudo-code of the whole parent transaction (include the
automonus transaction) part?
BTW, is there any hole in the sequence number for one customer? Do you
care this?
Such as:
custrec
-------
cust# seq#
10 1
10 2
10 5 <==
10 6
Regards,
FRX

Prince Kumar wrote:
I have a requirement where I have to generate sequnce like numbers
within another key.

My table is like,

custrec
-------
cust# seq#
10 1
10 2
10 4
10 5

20 1
20 2
20 3
20 4

..
..

For various reasons, I can not use sequnces. In Oracle I have a table
with as the following, which keeps the last sequnce number for each
cust# and autonomous transaction updates the maxseq#.

mastseq:
--------
cust# maxseq#
------ -------
10 5
20 4

Is there any way, I can get the same thing done in DB2.

Note, I do not want to select the maxseq# with "for update of", as
this will hold the lock until the transaction is complete. Also, I can
not commit the record immediately after updating the maxseq# within
the cust#, as this means inconsistent transaction.

Any Alternatives are welcome.

thanks,


Nov 12 '05 #4
Of course, everyone one will use "for update of", because the
application has the same SQL for everyone.

The suggested solution will not work for me, as I can not commit
immediately after getting the next record. In this case, I may be in
the middle of the transaction.

Also, Somewhat related to this. Is there anything similar to
sequences/identifiers in the partitioned DB? I believe sequences are
not allowed on partitioned db. What substitute DB2 has it here?

Thanks,

"Mark A" <ma@switchboard.net> wrote in message news:<%7*****************@news.uswest.net>...
"Prince Kumar" <gs**@yahoo.com> wrote in message
news:62**************************@posting.google.c om...
I have a requirement where I have to generate sequnce like numbers
within another key.

My table is like,

custrec
-------
cust# seq#
10 1
10 2
10 4
10 5

20 1
20 2
20 3
20 4

..
..

For various reasons, I can not use sequnces. In Oracle I have a table
with as the following, which keeps the last sequnce number for each
cust# and autonomous transaction updates the maxseq#.

mastseq:
--------
cust# maxseq#
------ -------
10 5
20 4

Is there any way, I can get the same thing done in DB2.

Note, I do not want to select the maxseq# with "for update of", as
this will hold the lock until the transaction is complete. Also, I can
not commit the record immediately after updating the maxseq# within
the cust#, as this means inconsistent transaction.

Any Alternatives are welcome.

thanks,


The lock held (SIX) with "for update of" will not lock out others who are
only doing selects. It will only lock others who are doing "for update of"
on the same row (and of course for direct updates of the data).

The actual exclusive lock (X) takes place when the "update where current of
cursor..." is issued. As long as you commit soon after that, you should be
OK.

Nov 12 '05 #5
SEQUENCE and IDENTITY are supported in DPF starting with V8 FP2

Cheers
Serge
Nov 12 '05 #6
Thanks Serge for the information.

"Serge Rielau" <sr*****@ca.eyebeem.com> wrote in message news:<bo**********@hanover.torolab.ibm.com>...
SEQUENCE and IDENTITY are supported in DPF starting with V8 FP2

Cheers
Serge

Nov 12 '05 #7

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

Similar topics

38
by: Mike | last post by:
No flame wars, please! We're planning a move from a non-relational system to a relational system. Our choices have been narrowed to Oracle and DB2. Since we're moving from non-relational to...
125
by: Rhino | last post by:
One of my friends, Scott, is a consultant who doesn't currently have newsgroup access so I am asking these questions for him. I'll be telling him how to monitor the answers via Google Newsgroup...
7
by: Rhino | last post by:
I am using DB2 V7.2.7 on Windows XP and I would like to write Ant 1.6.1 scripts that do some of my program preparation. For the benefit of those not familiar with Ant, it is an open source...
4
by: Abram Friesen | last post by:
Hi, I'm a developer for a software application vendor, and our application makes use of a customer-maintained Oracle 8i/9i database. We've had a customer request to support DB2 database, and I'm...
11
by: Mark A | last post by:
Here is Mark Townsend's (Oracle Product Manager) explanation and justification for posting in the DB2 newsgroup, as posted on the Oracle newsgroup, and my response: "Mark Townsend"...
3
by: Fred Morrison | last post by:
Does DB2 have anything equivalent to Oracle's PRAGMA AUTONOMOUS_TRANSACTION that allows a stored procedure to BEGIN, COMMIT or ROLLBACK a totally independent transaction while possibly (but not...
19
by: Gregor =?UTF-8?B?S292YcSN?= | last post by:
Hi! I'm using DB2 database on one server and ORACLE database on the second one. I want to move some data from ORACLE database to DB2 database and update some columns on ORACLE database so I know...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.