mysql儲存了儲存過程和函式的狀態資訊,使用者可以使用show status語句或show create語句來檢視,也可以直接從系統的information_schema資料庫中查詢。
1.使用show status語句檢視儲存過程和函式的狀態
【例1】show status語句示例,**如下:
"show procedure status like 『c%』 \g"語句獲取資料庫中所有名稱以字母』c』開頭的儲存過程的資訊。通過上面的語句可以看到:這個儲存函式所在的資料庫為 company,儲存函式的名稱為countproc等一些相關資訊。mysql>
show
procedure
status
like
'c%' \g**
****
****
****
****
****
****
*1.row***
****
****
****
****
****
****
db: company
name: countproc
type: procedure
definer: root@localhost
modified: 2019-08
-3114:16:21
created: 2019-08
-3114:16:21
security_type: definer
comment:
character_set_client: gbk
collation_connection: gbk_chinese_ci
database collation: utf8mb4_0900_ai_ci
1rows
inset
(0.09 sec)
2.使用show create語句檢視儲存過程和函式的定義
除了show status之外,mysql還可以使用show create語句檢視儲存過程和函式的狀態。
show create sp_name;
這個語句是乙個mysql的擴充套件,類似於show create table,它返回乙個可用來重新建立已命名子程式的確切字串。procedure和function分別表示檢視儲存過程和函式:sp_name引數表示匹配儲存過程或函式的名稱。
【例3】show create語句示例,**如下:
可以看到儲存過程的名稱為countprocl、sql_mode為sql模式、create function為儲存函式的具體定義語句,以及資料庫設定的一些資訊。mysql>
show
create
procedure countprocl \g**
****
****
****
****
****
****
*1.row***
****
****
****
****
****
****
procedure: countprocl
sql_mode: strict_trans_tables,no_engine_substitution
create
procedure: create
definer
=`root`
@`localhost`
procedure
`countprocl`
(in sid int
,out num int
)begin
select
count(*
)into num from fruits where s_id = sid;
endcharacter_set_client: gbk
collation_connection: gbk_chinese_ci
database collation: utf8mb4_0900_ai_ci
1row
inset
(0.00 sec)
3.從information_schema.routines表中檢視儲存過程和函式的資訊。
mysql中儲存過程和函式的資訊儲存在information_schema資料庫下的routines表中,可以通過查詢該錶的記錄來查詢儲存過程和函式的資訊,基本語法形式如下:
【例4】從routines表中查詢名稱為countproc的儲存函式的資訊,sql語句如下:select
*from information_schema.routines
where routine_name=
'sp_name'
;
我的電腦上routines表為空…mysql>
select
*from information_schema.routines
->
where routine_name =
'countproc'
and routine_type =
'function' \g
empty set
(0.01 sec)
在information_schema資料庫下的routines表中,儲存所有儲存過程和函式的定義。使用select語句查詢routines表中的儲存過程和函式的定義時,一定要使用routine_name欄位指定儲存過程或函式的名稱,否則將查詢出所有的儲存過程或函式的定義,如果有儲存過程和儲存函式名稱相同,就需要同時指定routine_type欄位表名查詢的是哪種型別的儲存程式。
MySQL 檢視儲存過程和函式
用 show status 語句可以檢視儲存過程和函式的狀態,其基本的語法結構如下 show status like pattern show status 語句是 mysql 的乙個擴充套件。它返回子程式的特徵,如資料庫 名字 型別 建立者及建立和修改日期。如果沒有指定樣式,根據使用的語句,所有的...
mysql檢視儲存過程函式
查詢資料庫中的儲存過程和函式 select name from mysql.proc where db xx and type procedure 儲存過程 select name from mysql.proc where db xx and type function 函式 show proce...
MYSQL檢視儲存過程函式
查詢資料庫中的儲存過程和函式 select name from mysql.proc where db xx and type procedure 儲存過程 select name from mysql.proc where db xx and type function 函式 show proce...