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 > How to check if a view does exist ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-17-09, 21:17
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
How to check if a view does exist ?

Hi,

I need some IF THEN construct to drop some views at beginning of the scheduled job.

For example I want to see if view exists and delete it before proceeding.

Quote:
IF EXIST VIEW ABC THEN
DROP VIEW ABC
END
;
Anything in DB2 SQL that may allow me to drop view ABC.

If I try straight
Quote:
DROP VIEW ABC ;
then schedule will be terminated when view does not exit.

Any Idea will be appreciated

DBFinder
Reply With Quote
  #2 (permalink)  
Old 08-18-09, 01:52
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
Wrap the logic in a SP
or if you are on 9.7 .. you can have execute immediate within compound stmts

begin declare continue handler for sqlstate '42704' begin /* Ignore */ end@ - comp.databases.ibm-db2 | Google Groups
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #3 (permalink)  
Old 08-19-09, 06:02
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Thanks Rahul Singh
Reply With Quote
  #4 (permalink)  
Old 08-19-09, 17:41
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
You can use something like this:

Quote:
select 1 from sysibm.sysviews
where name = '<<view name>>'
and creator = '<<view creator>>'
fetch first row only

if sqlcode = 0
drop view <<view name>>
end-if
....
Lenny
Reply With Quote
  #5 (permalink)  
Old 08-20-09, 09:37
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Yes Lenny,

This is great idea , SELECTing won't find anything and sqlcode will be non-zero.

So I can use it in Stored Procedure.

Can you suggest me how can I use it in Command Script box of Task Center.

Thanks
Reply With Quote
  #6 (permalink)  
Old 08-21-09, 15:20
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Quote:
Originally Posted by DBFinder
Yes Lenny,

This is great idea , SELECTing won't find anything and sqlcode will be non-zero.

So I can use it in Stored Procedure.

Can you suggest me how can I use it in Command Script box of Task Center.

Thanks
You can do it. Just use this logics.

Lenny
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