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 > anonymous blocks ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-03-04, 00:57
SamCute SamCute is offline
Registered User
 
Join Date: Mar 2004
Posts: 205
anonymous blocks ?

Hi,

I like to write the below procedure as an anonymous block( as in SQL Server ). How to do the same ? Please explain how to compile and call that block, if return so.

create procedure testproc
begin
if exists(select *from syscat.tables where tabschema = 'DB2' and tabname = 'TESTVIEW' and type ='V') then
drop view testview;
end if;
create view testview as select * from test;
end
@

Thanks,
Sam
Reply With Quote
  #2 (permalink)  
Old 08-03-04, 06:10
vidyaraok vidyaraok is offline
Registered User
 
Join Date: Aug 2004
Posts: 15
anonymus blocks

you can write the commnads in a file. and from db2 command window:

db2 -td@ -f file-name

or u can use command center script tag. in tool settings set command terminating character as @.
Reply With Quote
  #3 (permalink)  
Old 08-03-04, 06:19
SamCute SamCute is offline
Registered User
 
Join Date: Mar 2004
Posts: 205
Thanks for your reply.

Yes, you are right. This is ok with a 'create procedure'.
But my requirement is an anonymous block, i.e without a 'CREATE PROCEDURE' statement. In this case I need to execute only these statement :

if exists(select *from syscat.tables where tabschema = 'DB2' and tabname = 'TESTVIEW' and type ='V') then
drop view testview;
end if;
create view testview as select * from test;

But the above is not compiling, when I give the same in a file. how to compile this and even if it gets compiled, how to call this anonymous block for execution ?

(as in SQL Server - anonymous block)

Thanks,
Sam
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