IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Can we Update cursor with group by and union ?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vyasricha

New User


Joined: 17 Mar 2008
Posts: 27
Location: banaglore

PostPosted: Sat May 26, 2012 11:05 am
Reply with quote

Hi,

I am defining a cursor with group by and union. and i am updating the same table as per the data fetched from cursor.

when i am running the query it is taking 10 minutes to fetch the data , but while defining the cursor in cobol-db2 program it is taking an hour to open the cursor ,the table doesn't have much data in table it has only 3000 rows but still an hour.
Please let me know if i am making any mistakes in program.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat May 26, 2012 4:17 pm
Reply with quote

oh, i am sure that you are not making any mistakes in your program,
but i image that your sql sucks.
does group by and / or union make a cursor read only?

a group by would consolidate rows from the base table and generate fewer row(s) for the result table. can not update the result table.

suggest you go back and read the discussions in the application programmers guide
about what makes a read only cursor and an update cursor.

if there is more than 1 table mentioned in the cursor definition,
it is a read only.

i do not think that you can use a update current cursor on a cursor that you have described,
but then i only have your word for it.

the hour that you speak of to open the cursor,
is your time, not machine time.
Back to top
View user's profile Send private message
vyasricha

New User


Joined: 17 Mar 2008
Posts: 27
Location: banaglore

PostPosted: Mon May 28, 2012 10:52 am
Reply with quote

so i can not update the same table if i am defining the cursor with group by, sum and joins.

SELECT xx_CLIENT_ID
FROM AA.DXX_CLIENT
WHERE XX_MTH = :Processing Month
AND XX_YEAR_MTH = :Processing Year / Month
AND XX_CLIENT_ID <> ' '
AND XX_CLASS = ‘ABCD’
AND XX_RT_LVL_PRD_CAT IN ('ABCD’, 'EFGH’, 'IJKL’)
GROUP BY XX_CLIENT_ID
HAVING SUM(XX__AMT) > 125000

If data is there i am updating the same table .

The job is taking long time to run , is there is some problem in cursor definition ?
Back to top
View user's profile Send private message
Smita.t2

New User


Joined: 17 Apr 2012
Posts: 31
Location: Bangalore

PostPosted: Mon May 28, 2012 12:25 pm
Reply with quote

Please check if STATS is collected for tables/indexes. If not, u may need to run Runstats aganist table/indexes and rebind the program.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Mon May 28, 2012 1:26 pm
Reply with quote

You can use EXPLAIN to check which indexes this query is using? May be its doing tablespace scan on one of the table

Thanks and regards,
Chandan
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue May 29, 2012 12:05 am
Reply with quote

Hello,

I suspect there are "things missing" from the post. . .

Taking an hour to process 3000 rows is surely questionable.

The posted code is a select from only 1 table even though the initial dialog mentions union. It is not in the posted sql icon_confused.gif

How many tables are in this tablespace?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Compare latest 2 rows of a table usin... DB2 1
No new posts Read a flat file and update DB2 table JCL & VSAM 2
No new posts how to update an ISR appl var from an... TSO/ISPF 8
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
No new posts Splitting group records based on deta... DFSORT/ICETOOL 8
Search our Forums:

Back to Top