简体   繁体   中英

Getting the parameter names by giving the procedure name - MySQL

有没有办法通过在MySQL中给出过程名称和数据库名称来获取数据库中存储过程的参数名称?

Previously, I gave a solution using mysql.proc . @Michael-sqlbot pointed out that it would be much better to use information_schema.parameters . This revised solution follows that suggestion.

Execute these queries to describe and illustrate the data in information_schema.parameters :

EXPLAIN information_schema.parameters;
SELECT * FROM information_schema.parameters;

This is the revised solution:

SELECT parameter_name 
  FROM information_schema.parameters
 WHERE specific_schema = 'my_db'
   AND specific_name = 'my_procedure'
 ORDER BY ordinal_position
;

parameter_name
-----------------
p_first_param
p_second_param
p_third_param

If you need them in a single row, GROUP_CONCAT could be used to give you comma-separated names:

SELECT GROUP_CONCAT(parameter_name) params 
  FROM information_schema.parameters
 WHERE specific_schema = 'my_db'
   AND specific_name = 'my_procedure'
 ORDER BY ordinal_position
;

params
------------------------------------------
p_first_param,p_second_param,p_third_param

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM