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 get list of all store procedures that are related to specific table?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-22-10, 07:05
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
How to get list of all store procedures that are related to specific table?

Hi,
using db2 v9.5 on Linux I would like to get list of all SQL store procedures that are related to specific table.

Sample:
Code:
CREATE PROCEDURE ADMIN.STORE_PROCEDURE
  (
    IN INspID INT,
    OUT OUTspID         INT,
    OUT OUTspUSERTYPE   CHARACTER  (20)
   )
  LANGUAGE SQL
  BEGIN
        SELECT
            ID, USERTYPE
        INTO
            OUTspID, OUTspUSERTYPE
        FROM
           ADMIN.MY_TABLE
        WHERE
            ID = INspID
        ;
  END
@
In the above sample is there any way I could write some select statement against SYSCAT views to get all store procedures where ADMIN.MY_TABLE is included in select/insert/update/delete statement? So answer to this query would be ADMIN.STORE_PROCEDURE, because it includes ADMIN.MY_TABLE in select statement.

Thanks
Reply With Quote
  #2 (permalink)  
Old 10-22-10, 07:29
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Check the catalog view SYSCAT.ROUTINEDEP.
Reply With Quote
  #3 (permalink)  
Old 10-22-10, 11:29
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Please note, this will work only for Static Statements.

If you use dynamic sql, this approach will not work and afaik, there is no definitive way of finding this info

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #4 (permalink)  
Old 10-25-10, 03:48
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Thanks for help. I have managed to write an SQL to get a list of stored procedures that are related to specific table.
Code:
SELECT
    SUBSTR(C.ROUTINESCHEMA,1,15) AS PSCHEMA,
    SUBSTR(C.ROUTINENAME,1,15) AS PNAME, 
    C.TEXT
FROM
    SYSCAT.PACKAGEDEP A,
    SYSCAT.ROUTINEDEP B,
    SYSCAT.ROUTINES C
WHERE
    A.PKGSCHEMA=B.BSCHEMA AND
    A.PKGNAME=B.BNAME AND
    B.ROUTINESCHEMA=C.ROUTINESCHEMA AND
    B.ROUTINENAME=C.SPECIFICNAME AND
    A.BSCHEMA='ADMIN' AND
    A.BNAME ='MY_TABLE'
Note: my table name is ADMIN.MY_TABLE
Reply With Quote
Reply

Tags
stored procedures

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