Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Extracting the View scripts of a table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Bhuvanesh Subburajan

New User


Joined: 06 Jan 2012
Posts: 2
Location: India

PostPosted: Thu Mar 14, 2013 3:26 pm    Post subject: Extracting the View scripts of a table
Reply with quote

Hi

I am developing a tool to retrieve the DDL statements used for creating the views of the given table. Initially, I was extracting the view scripts of the given Table by retrieving the TEXT column of the SYSIBM.SYSVIEWS table by joining with the SYSIBM.SYSVIEWDEP table using the given table name and schema.

Now I have a requirement in which I have to retrieve the texts all the dependent views on this table i.e., the views which are dependent on the views created using the original tables. I have even coded a SQL statement for that too. PFB the code for that statement

Code:


 SQL_STMT_VDF2 = "SELECT A.TEXT FROM SYSIBM.SYSVIEWS A", 
                 "INNER JOIN SYSIBM.SYSVIEWDEP B",       
                 "ON A.NAME = B.DNAME AND B.BTYPE = 'V'",
                 "INNER JOIN SYSIBM.SYSVIEWDEP C",       
                 "ON B.BNAME = C.DNAME",                 
                 "WHERE C.BNAME = ?",                     
                 "AND C.BCREATOR = ?"                     


My query is what if I want to extract the views that are dependent on the view's view or view's view's view and so on.

Let me rephrase it

I want to extract the create text of the all the views that are associated with the given table irrespective of whether it is dependent of the table directly or to the views of the table. What can I do?
Back to top
View user's profile Send private message

GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Thu Mar 14, 2013 7:18 pm    Post subject:
Reply with quote

write a recursive SQL :
Code:
with CTE(cnt, creator, name, depcreator, depname) as
  (select 1 , DCREATOR ,DNAME, bcreator, bname
     from sysibm.sysviewdep
    where bname = ? and BCREATOR = ?
   union all
   select cte.cnt + 1 , dcreator, dname, bcreator, bname
     from sysibm.sysviewdep, cte
    where BCREATOR= cte.creator and  BNAME = cte.name
      and cte.cnt < 5)

select cte.cnt, v.creator, v.name
     , cast(v.text as varchar(10000))
  from cte
     , sysibm.sysviews V
where v.name = cte.name and v.creator = cte.creator
Back to top
View user's profile Send private message
Bhuvanesh Subburajan

New User


Joined: 06 Jan 2012
Posts: 2
Location: India

PostPosted: Fri Mar 15, 2013 3:31 pm    Post subject: Reply to: Extracting the View scripts of a table
Reply with quote

Its working icon_smile.gif

Thank you so much icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Command UNIQUE CONSTRAINT on any tabl... rohanthengal DB2 2 Thu Aug 18, 2016 3:48 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us