If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > db2 inline dynamic sql doesn't output result

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-27-09, 09:58
wondering wondering is offline
Registered User
 
Join Date: May 2009
Posts: 10
db2 inline dynamic sql doesn't output result

i am studying db2 dynamic sql.

I wrote this very simple script test.sql:

begin atomic
select * from table1 fetch top 5 rows only;
end@

Invoking this script with:
db2 -td@ test.sql -z test.log

The test.log does't contain the result, only one message saying the command succeeded.

If I change the test.sql to be non-inline:
select * from table1 fetch top 5 rows only@

then the test.log contains 5 records.

Could you please kindly explain why this is the case?
Reply With Quote
  #2 (permalink)  
Old 05-27-09, 10:06
wondering wondering is offline
Registered User
 
Join Date: May 2009
Posts: 10
sorry, didn't say the version of DB2. I use client API to connect to DB2 server, and the client API is 8. So I guess I am using DB2 8?
Reply With Quote
  #3 (permalink)  
Old 05-27-09, 10:56
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The CLP only works on statements, one at a time. In your first scenario, you have just one statement, it happens to be a compound statement. Whatever that compound statement does internally is not reported back, just the results of the entire statement. Compound statements are usually reserved for doing atomic work (update, insert, delete), not returning result sets.

Andy
Reply With Quote
  #4 (permalink)  
Old 05-28-09, 02:28
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
to return a result set use stored procedure instead
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On