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 > db2look to get a stored procedure DDL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-14-08, 12:58
db2rocks db2rocks is offline
Registered User
 
Join Date: Jan 2008
Posts: 45
db2look to get a stored procedure DDL

Hi friends,

I am coding a shell script that takes a procedure name as input and gives the DDL of procedure as output by parsing db2look output.I am checking for create procedure statement and then checking for END statement followed by semicolon.

Do you think the above logic would work for all kinds of SQL stored procedure??

Thanks
Reply With Quote
  #2 (permalink)  
Old 02-14-08, 14:09
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
No, because if the SP has an internal BEGIN-END block you would terminate too early. Have you tried:

select text from syscat.routines where ...

This will get you the entire CREATE PROCEDURE for SQL procedures. I have seen the CLP truncate the return though.

Andy
Reply With Quote
  #3 (permalink)  
Old 02-14-08, 14:51
db2rocks db2rocks is offline
Registered User
 
Join Date: Jan 2008
Posts: 45
Thanks for the reply.You are right there might be inner END statements..How about counting the number of BEGIN and number of END statements??

What you said is 100% correct.Extracting from syscat.routines.But I am always getting lot of garbage when i do that.
Reply With Quote
  #4 (permalink)  
Old 02-14-08, 15:29
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
If you are going to count BEGIN and END statements, then you are also going to have to count IF, LOOP, WHILE, and every other statement that ends with END.

Andy
Reply With Quote
  #5 (permalink)  
Old 02-14-08, 16:43
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by ARWinner
you are also going to have to count IF, LOOP, WHILE, and every other statement that ends with END.
...but ignore comments that might contain "end", or string literals that might contain "end", or...
Reply With Quote
  #6 (permalink)  
Old 02-14-08, 17:55
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You can run db2look with specifying your own statement terminator (other than the default ";"). It will still use ";" at the end of each line, but will use the terminator you specify at the end of the SP. I prefer using the "@" symbol. This should solve your problem.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390

Last edited by Marcus_A; 02-15-08 at 16:19.
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