Retrieving the SQL underlying a Stored Procedure

Many moons ago,  I had written some code that used ADO/ADOX to retrieve the SQL underlying a stored procedure (for Oracle and MS SQL).  But,  I somehow lost that code and have been googling my head off looking for the method to repeat this function with.

Any and all help on this would be greatly appreciated.  I need this for Oracle and MS SQL and would prefer that the snippet was in VB.NET, but the language used for the answer here is not critical.

Thanks,
Howard
LVL 1
Howard BashSenior Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chapmandewCommented:
in 2005 you can do this:


select object_definition(object_id)
from sys.procedures
where name = 'procedurename'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SujithData ArchitectCommented:
For Oracle, use this query.

select text from user_source where name = upper('your procedure name') order by type, line;
0
SujithData ArchitectCommented:
If the procedure belongs to another oracle user you may have to change the query to use all_source
or dba_source. something like

select text from all_source where owner = upper('user name') and name = 'TEST_PROC' order by type, line;
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Howard BashSenior Software EngineerAuthor Commented:
While both these queries work in their respective environments,  I was hoping to use something more generic like the ado/adox catalog object, etc...

Please advise.

Thanks,
Howard
0
Howard BashSenior Software EngineerAuthor Commented:
When I run this at home,  it fails with
Msg 195, Level 15, State 10, Line 2
'object_definition' is not a recognized function name.

When I type:
SELECT  SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')

I get back the following:
8.00.2273      SP4      Standard Edition

0
chapmandewCommented:
if you're using 2000, do this:


select text from syscomments
where object_name(object_id) = 'tablename'
0
Howard BashSenior Software EngineerAuthor Commented:
By table name,  do you mean "Stored Procedure" name?
0
chapmandewCommented:
yeah, sorry about that....procedure name.  (have had a long day)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.