Welcome ...        
          
  ... Visiting Newsgroup Users!
 
  See "What makes SQLA different from the newsgroups?" in the FAQ.
 
vote up 3 vote down
star

What SQL do I use to get a list of functions and a list of procedures from the database? I need to get two distinct lists. This SQL brings back both procedures and functions in one list:

select b.name + '.' + a.name, a.id, a.crdate, '', 0, ''
from sysobjects a, sysusers b
where a.type = 'P'
and a.uid = b.uid
order by b.name, a.name

Thanks,

Brad

flag

1 Answer

vote up 5 vote down
check

SQLA: 10.0.1
This may not be the best solution, but I couldn't another way to determine one from the other.

select 
    su.user_name + '.' + sp.proc_name as Full_Name, 
    CASE substr(left(proc_defn,8), 8, 1) 
        WHEN 'p' THEN 'Procedure' 
        WHEN 'f' THEN 'Function' 
    END as Object_Type 

from 
    sysprocedure sp, 
    sysuser su 

where 
    sp.creator = su.user_id 

order by 
    su.user_name, 
    sp.proc_name

Then, of course, you could restrict based on Object_Type.

Hope it helps!

link|flag
I'll go with this for now. It works, that's all I need right now. – Brad Wery Jan 5 at 23:33
It probably is the best solution. Sadly, the system catalog tables don't differentiate, with sysobject.object_type = 6 for both. – Breck Carter Jan 6 at 11:35
...Which leads to the question, how the database server differentiantes between both types? Or is this done in a context-sensitive way, i.e. CALL myFunction(1) is somewhat different from SELECT myFunction(1)? (AFAIK, using functions quite like procedures - including INOUT parameters and the like - is possible in older SA versions, adding to the conclusion that both types are more similar than expected). – Volker Barth Jan 6 at 11:55
Yeah, there are also calls to 'drop procedure' and 'drop function'. How do they work? – Calvin Allen Jan 6 at 17:29
Nevermind, I just answered my own question. 'drop procedure' will drop functions, and 'drop function' will drop procedures. Strange implementation. – Calvin Allen Jan 6 at 19:41

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.