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

Error in using both ORDER BY and FOR UPDATE OF in a SQL


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

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Thu Aug 16, 2007 7:54 pm
Reply with quote

Hi,
I tried the cursor .

Code:
DECLARE XYZ CURSOR WITH HOLD FOR             
         SELECT SL_ADJ_ENT_ID                                 
                 ,ACCT_ID                                       
               ,ENT_ID                                       
               ,SL_RQST_STAT_CD                               
               ,SL_SUB_STAT_CD                               
               ,SL_ADJ_RQST_AM                               
               ,SL_ADJ_TRANS_CT                               
               ,ACCT_EVNT_CD                                 
               ,SL_ADJ_CR_ACCT_ID                             
               ,SL_ADJ_DB_ACCT_ID                             
               ,SL_ADJ_SUS_ACCT_ID                           
               ,PER_SL_ADJ_END_DT                             
             
           FROM SJRT_SL_ADJ_RQST                             
          WHERE SL_RQST_STAT_CD    = :SJR-SL-RQST-STAT-CD     
            AND SL_SUB_STAT_CD     = :SJR-SL-SUB-STAT-CD     
            ORDER BY SL_ADJ_ENT_ID                                 
  FOR UPDATE OF SL_RQST_STAT_CD, SL_SUB_STAT_CD     


The precompiler threw a error message as
Quote:
"ORDER BY" CANNOT BE USED WITH A "FOR UPDATE OF" CLAUSE


Is it not possible to use a group by with an 'UPDATE FOR' clause? If no, is there any other way to order the rows fetched from a cursor for update in a particular way?
I am using DB2 Version 7
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Aug 16, 2007 8:10 pm
Reply with quote

quoted from my favorite DB2 author Craig Mullins:

You cannot code the FOR UPDATE OF clause on cursors that access read-only data. These cursors contain SELECT statements that
  • Access read-only views
  • Join any tables
  • Issue subqueries for two or more tables
  • Access two or more tables using UNION
  • Use built-in functions
  • Use ORDER BY, GROUP BY, or HAVING
  • Specify DISTINCT
  • Specify literals or arithmetic expressions in the SELECT list
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Thu Aug 16, 2007 8:27 pm
Reply with quote

Thanks Dick..The info was very useful...
Back to top
View user's profile Send private message
deepak.vl

New User


Joined: 17 Feb 2007
Posts: 38
Location: Hyderabad

PostPosted: Fri Aug 24, 2007 6:24 pm
Reply with quote

But the cursor with ORDER BY clause doesn't necessary be a read-only. It should be updatable since what we are fetching is exactly a complete row from the table. What do u say?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Aug 24, 2007 6:36 pm
Reply with quote

deepak.vl,

I say you need to accept the definitions that IBM provides.

An ORDERED BY results table is read-only, per IBM. (Just like the speed limit is x, regardless of the traffic!)

Besides, you are not FETCHing complete rows from the base table,
you are FETCHing rows from the results table.

And to update a row, in an properly defined CURSOR FOR UPDATE,
you do not need to select all the columns in a row, only those that you plan to UPDATE and those that you need for your application processing.
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 Error to read log with rexx CLIST & REXX 11
No new posts Error when install DB2 DB2 2
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts Rotate partition-logical & physic... DB2 0
No new posts Error while running web tool kit REXX... CLIST & REXX 5
Search our Forums:

Back to Top