10

Is there any options to view stored procedure/function code in MySql same as like "sp_helptext procedurename" in sql?

shgnInc
  • 2,054
  • 1
  • 23
  • 34
User129
  • 129
  • 1
  • 1
  • 9

5 Answers5

18

try "SHOW CREATE PROCEDURE procedurename"

codelization
  • 189
  • 3
  • 1
    **1.** SHOW with CREATE is usually available, (just SHOW is only available in debug mode)........................ **2.** This **shows the whole CREATE code** of the function/procedure. – jave.web Apr 08 '14 at 05:57
  • 2
    Also note that of course you can switch `procedure` keyword with `function` to get the function create code::::: `SHOW CREATE FUNCTION function_name` – jave.web Apr 08 '14 at 06:04
7

Yes,

SELECT ROUTINE_DEFINITION FROM information_schema.ROUTINES WHERE SPECIFIC_NAME='procedurename'
Christoph
  • 1,993
  • 1
  • 25
  • 33
  • This **shows what the function/procedure CONTAINS** - what is to be executed, not the whole "create function/procedure" code. – jave.web Apr 08 '14 at 06:05
0

You can get the information form the INFORMATION_SCHEMA.ROUTINES table

Maxim Krizhanovsky
  • 26,265
  • 5
  • 59
  • 89
0

I've been experimenting a bit, and I think one of the following two works best.

To list everything (parameters, collating, etc.), use this.

 SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA in (SELECT DATABASE()) AND ROUTINE_NAME='ProcedureName';

To list only the code, use this.

SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA in (SELECT DATABASE()) AND ROUTINE_NAME='ProcedureName';

In both of the above, the nested select is required to limit the result to the current database, since INFORMATION_SCHEMA, being the system database, contains details for every database installed in the instance.

Useme Alehosaini
  • 2,998
  • 6
  • 18
  • 26
David A. Gray
  • 1,039
  • 12
  • 19
0

Go to mySQL workbench

  • Right click on procedure and then select ALTER. (This Will open the definition of procedure for you(is the easiest way).

OR

  • You can also use the command, SHOW CREATE PROCEDURE proc_name;
Ali
  • 2,702
  • 3
  • 32
  • 54