Get Stored Procedure Source Text - Sybase Adaptive Server Enterprise

In Sybase ASE you can use sp_helptext system procedure to output the source code of a stored procedure:

Sybase ASE:

  -- Specify the name of your procedure 
  sp_helptext showOrdersSummary

Result (2 result sets):

# Lines of Text
3
text
CREATE OR REPLACE PROCEDURE showOrdersSummary …
SELECT @region_out …
CLOSE cur2 DEALLOCATE cur2 …

sp_help_text returns 2 results set, one showing the number of lines in the stored procedure, another is actual text in chunks of 255 characters per row.

Using a Catalog Query

You can also use a catalog query to get the same information, and it can be useful if you need to get the source code for multiple stored procedures:

Sybase ASE:

  SELECT u.name, o.name, c.text
  FROM sysusers u, syscomments c, sysobjects o 
  WHERE o.type = 'P' AND o.id = c.id AND o.uid = u.uid
  ORDER BY o.id, c.colid

Result:

dbo showOrdersSummary CREATE OR REPLACE PROCEDURE showOrdersSummary …
dbo showOrdersSummary SELECT @region_out …
dbo showOrdersSummary CLOSE cur2 DEALLOCATE cur2 …
dbo getUsers CREATE PROCEDURE getUsers …

For more information, see: