View previous topic :: View next topic |
Author |
Message |
wdnealis Beginner
Joined: 17 Jan 2006 Posts: 25 Topics: 4
|
Posted: Mon Aug 14, 2006 2:24 pm Post subject: DB2 Primary Key UPDATE on a Partitioned Table. |
|
|
Hi,
I am fetching values and trying to update the Primary Key on a partitioned table, but keep getting a -803 SQLCODE. I also, tried a delete, insert, but the -803 is still occuring. Any ideas on resolve this issue?
Code: |
PERFORM D500-GET-MAX-SEQUENCE
PERFORM D600-ORB-FILE-UPDATE
D500-GET-MAX-SEQUENCE.
EXEC SQL
SELECT MAX(SQNC_NUM)
INTO :WS-SQNC-NUM
,:WS-AUDT-SQNC-IND
FROM DB2ADMIN.MBQ_LIS_ORB_FIL
WHERE TRACE_NO = :WS-NO
AND CD = :WS-CD
AND STRT_DT = :WS-STRT-DT
AND SRC = :WS-SRC
AND ERRW = :WS-ERR-SW
AND OCRNC = :WS-OCRNC
END-EXEC.
EVALUATE SQLCODE
WHEN +0
CONTINUE
WHEN +100
MOVE ZEROES TO WS-SQNC-NUM
WHEN OTHER
DISPLAY 'SQL ERROR ON GET MAX.'
END-EVALUATE.
COMPUTE WS-HOLD-SQNC = WS-SQNC-NUM + 1
MOVE WS-HOLD-SQNC TO WS-SQNC-NUM.
MOVE '2' TO ERR-SW.
D600-ORB-FILE-UPDATE.
MOVE 'D600-ORB-FILE-UPDATE' TO WS-CALL-LABEL.
EXEC SQL
UPDATE DB2ADMIN.MBQ_LIS_ORB_FIL
SET ERR_SW = '2'
,SQNC_NUM = :WS-SQNC-NUM
,REC_UPDT_TS = CURRENT TIMESTAMP
WHERE TRACE_NO = :WS-TRACE
AND CD = :WS-CD
AND STRT_DT = :WS-STRT-DT
AND SRC = :WS-SRC
AND ERR_SW = '1'
AND OCRNC = :WS-OCRNC
END-EXEC.
EVALUATE SQLCODE
WHEN +0
ADD 1 TO WS-PROCESSED-REC-CNT
WHEN OTHER
DISPLAY 'SQL ERROR ON UPDATE.'
END-EVALUATE.
TRACE_NO CD START_DT SRC ERR SQNC
--------- -- ---------- --- --- ------
999999010 07/01/2005 SS 1 0
999999010 07/01/2005 SS 2 0
999999010 07/22/2005 SS 1 0
999999020 07/01/2005 SS 1 0
999999020 07/01/2005 SS 2 0
999999020 07/01/2005 SS 2 1
999999020 12/01/2005 SS 1 0
999999030 07/01/2005 SS 1 0
999999030 07/01/2005 SS 2 0
999999030 07/17/2005 SS 1 0
999999040 07/01/2005 SS 1 0
999999040 07/01/2005 SS 2 0
999999040 07/24/2005 SS 1 0
999999050 07/01/2005 SS 1 0
999999050 07/01/2005 SS 2 0
999999050 07/22/2005 SS 1 0
999999060 08/01/2005 SS 1 0
999999060 08/05/2005 SS 2 0
999999060 01/01/2006 SS 1 0
999999070 07/01/2005 SS 1 0
999999070 07/01/2005 SS 2 0
999999070 05/01/2006 SS 1 0
999999080 07/01/2005 SS 1 0
999999080 07/01/2005 SS 2 0
999999080 07/24/2005 SS 1 0
999999090 07/01/2005 SS 1 0
999999090 07/01/2005 SS 2 0
999999090 07/02/2005 SS 1 0
|
|
|
Back to top |
|
|
coolman Intermediate
Joined: 03 Jan 2003 Posts: 283 Topics: 27 Location: US
|
Posted: Mon Aug 14, 2006 2:38 pm Post subject: |
|
|
The values you are updating are ERR_SW, a SQNC_NUM and a timestamp
From your code, I can see that ERR_SW is always 2, SQNC_NUM is going to fetch the max no of rows in a table and I can't see that changing because there's just an update statement. The only variable entity that I can see here is the CURRENT TIMESTAMP. And I guess these 3 fields form the key. Is this correct?
Can you find this out ? Are you getting a -803 only when SQLCODE = 100 from the select query coz in this case, you just reset the sequence number to zero and then then downstream, you increase it back to 1 and who knows such a sequence might exist out there !!!
________
Luca Marmorini
Last edited by coolman on Sat Feb 05, 2011 1:47 am; edited 1 time in total |
|
Back to top |
|
|
wdnealis Beginner
Joined: 17 Jan 2006 Posts: 25 Topics: 4
|
Posted: Mon Aug 14, 2006 3:02 pm Post subject: |
|
|
No. All five columns are the key, and that's a date field, not TS. The update is to fetch and change all ERR_SW from '1' to '2', and the MAX SQNC is the only other field that changes on the key. The -803 is on various conditions. |
|
Back to top |
|
|
coolman Intermediate
Joined: 03 Jan 2003 Posts: 283 Topics: 27 Location: US
|
Posted: Mon Aug 14, 2006 3:34 pm Post subject: |
|
|
What is OCRNC? I see that in the SQL statements but not as part of your table data depiction? Now that you've said it's only the data and not the timestamp, I'm pretty positive that the chances of a -803 are pretty high. The solution is simple but needs to be manually xpedited. Try printing out the values in the your DCLGEN values that you are trying to update with before attempting the update and do a query on the database to see if they really exist. Definitely, it's a primary key violation which causes this.
________
clear trichomes
Last edited by coolman on Sat Feb 05, 2011 1:47 am; edited 1 time in total |
|
Back to top |
|
|
wdnealis Beginner
Joined: 17 Jan 2006 Posts: 25 Topics: 4
|
Posted: Mon Aug 14, 2006 3:39 pm Post subject: |
|
|
OCRNC is the number of occurences.
I have displays and the values do not exist, but when the insert or update is executed the result is -803. |
|
Back to top |
|
|
coolman Intermediate
Joined: 03 Jan 2003 Posts: 283 Topics: 27 Location: US
|
Posted: Mon Aug 14, 2006 3:58 pm Post subject: |
|
|
1. Are you sure you are doing the queries and the programs being run are pointed to the same DB2 region?
2. Are you having a background trigger that gets executed when this update happens. This trigger might update some other table which might cause the -803.
________
Mercedes-Benz buses
Last edited by coolman on Sat Feb 05, 2011 1:48 am; edited 1 time in total |
|
Back to top |
|
|
wdnealis Beginner
Joined: 17 Jan 2006 Posts: 25 Topics: 4
|
Posted: Mon Aug 14, 2006 4:21 pm Post subject: |
|
|
1. Yes.
2. no triggers, and this is the only table being update. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Mon Aug 14, 2006 6:20 pm Post subject: |
|
|
wdnealis,
quite simple take this key
Code: |
TRACE_NO CD START_DT SRC ERR SQNC
--------- -- ---------- --- --- ------
999999010 07/01/2005 SS 1 0
999999010 07/01/2005 SS 2 0
999999010 07/22/2005 SS 1 0
|
For the first trace_no the max of sqnc is 0 and you are adding 1 to it and setting the ERR to 2. By doing so the
the first 2 rows will be as follows
Code: |
TRACE_NO CD START_DT SRC ERR SQNC
--------- -- ---------- --- --- ------
999999010 07/01/2005 SS 2 1
999999010 07/01/2005 SS 2 1
|
Which is a duplicate considering the 5 columns as a key
kolusu
Ps: Do not post the same question in more than 1 forum. Do not send private emails seeking help. _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
wdnealis Beginner
Joined: 17 Jan 2006 Posts: 25 Topics: 4
|
Posted: Tue Aug 15, 2006 7:32 am Post subject: |
|
|
You old post on this topic mentioned that "You can only update a primary key if the table is a stand alone table(no child table) or the table is not partitioned.", so I tried the delete/insert but -803 still occurr
_________________
Code: |
PERFORM D600-OLDREC-DELETE
PERFORM D500-GET-MAX-SEQUENCE
PERFORM D700-NEWREC-INSERT
D600-OLDREC-DELETE.
EXEC SQL
DELET FROM DB2ADMIN.MBQ_LIS_ORB_FIL
WHERE TRACE_NO = :WS-TRACE
AND CD = :WS-CD
AND STRT_DT = :WS-STRT-DT
AND SRC = :WS-SRC
AND ERR_SW = '1'
AND OCRNC = :WS-OCRNC
END-EXEC.
EVALUATE SQLCODE
WHEN +0
CONTINUE
WHEN OTHER
DISPLAY 'SQL ERROR ON DELETE.'
END-EVALUATE.
PERFORM D700-NEWREC-INSERT
EXEC SQL
INSERT INTO DB2ADMIN.MBQ_LIS_ORB_FIL
TRACE_NO
,CD
,STRT_DT
,SRC
,ERR_SW
,SQNC
,OCRNC
WHERE TRACE_NO = :WS-TRACE
AND CD = :WS-CD
AND STRT_DT = :WS-STRT-DT
AND SRC = :WS-SRC
AND ERR_SW = '2'
AND SQNC = :WS-SQNC-NUM
AND OCRNC = :WS-OCRNC
END-EXEC.
EVALUATE SQLCODE
WHEN +0
CONTINUE
WHEN OTHER
DISPLAY 'SQL ERROR ON DELETE.'
END-EVALUATE.
|
|
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Aug 15, 2006 7:51 am Post subject: |
|
|
wdnealis,
Why do you have a WHERE statement in your Insert statement? Did the code even complie?
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
wdnealis Beginner
Joined: 17 Jan 2006 Posts: 25 Topics: 4
|
Posted: Tue Aug 15, 2006 8:09 am Post subject: |
|
|
That's a typo, it's an Insert into, that should be VALUES.
And the SQNC is incremented, but the resutl is -803 eventhough the displaty shows that the value was increased. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Aug 15, 2006 8:23 am Post subject: |
|
|
wdnealis,
Even if you delete you are once again inserting the same row with '2' in err seqnum. So isn't it a duplicate? Also try adding a COMMIT in between the delete and insert.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
wdnealis Beginner
Joined: 17 Jan 2006 Posts: 25 Topics: 4
|
Posted: Tue Aug 15, 2006 9:25 am Post subject: |
|
|
I'm adding to the MAX SQNCto make it unique. |
|
Back to top |
|
|
wdnealis Beginner
Joined: 17 Jan 2006 Posts: 25 Topics: 4
|
Posted: Tue Aug 15, 2006 11:42 am Post subject: |
|
|
The COMMIT works fine.
Thanks again. |
|
Back to top |
|
|
|
|