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 > declare statement in db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-24-09, 00:17
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
Question declare statement in db2

Can we use
declare ......
begin
..............
end
alone without create procedure (like in Oracle) in db2?
My query is:

can i use this:

declare countValue integer;
begin
SET countValue=(select count(*) from SYSIBM.SQLTABLES where table_name=upper('vivek'));
if countValue=1
then
alter table dbo.vivek;
drop column dbo.name;
end if;
end


Plesae give me a solution
Thanks in advance
Vivek
Reply With Quote
  #2 (permalink)  
Old 01-24-09, 02:49
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
nope.... you'll have to create a proc... this would have been possible in MSSQL but not in DB2
__________________
IBM Certified Database Associate, DB2 9 for LUW
Reply With Quote
  #3 (permalink)  
Old 01-25-09, 14:16
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Yes, you can use atomic compound statements on the command line:
Code:
$ db2 "create table t ( a int )"
DB20000I  The SQL command completed successfully.
$ db2 "begin atomic declare i int default 0; while ( i < 10 ) do insert into t values ( i ); set i = i + 1; end while; end"
DB20000I  The SQL command completed successfully.
364 local:~/ $ db2 "select * from t"

A
-----------
          0
          1
          2
          3
          4
          5
          6
          7
          8
          9

  10 record(s) selected.
You may want to have a look at the SQL statements that you can place into such a compound statement.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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