A.4. MySQL 5.0 FAQ — 存储过程

Questions

26.4.1:

MySQL 5.0是否支持存储过程?

Does MySQL 5.0 support stored procedures?

26.4.2:

在哪可以找到MySQL的存储过程和函数的文档?

Where can I find documentation for MySQL stored procedures

and stored functions?

26.4.3:

哪里有关于MySQL存储过程讨论的地方呢?

Is there a discussion forum for MySQL stored procedures?

26.4.4:

在哪可以找到ANSI SQL 2003规范中关于存储过程的那部分?

Where can I find the ANSI SQL 2003 specification for stored

procedures?

26.4.5:

如何管理存储过程呢?

How do you manage stored routines?

26.4.6:

怎么查看一个指定数据库中的存储过程和函数?

Is there a way to view all stored procedures and stored

functions in a given database?

26.4.7:

存储过程保存在哪里呢?

Where are stored procedures stored?

26.4.8:

可否将存储过程分组或者把函数保存在包中?

Is it possible to group stored procedures or stored

functions into packages?

26.4.9:

存储过程中可否调用其他存储过程呢?

Can a stored procedure call another stored procedure?

26.4.10:

存储过程中能否调用触发器?

Can a stored procedure call a trigger?

26.4.11:

存储过程中能否访问数据表?

Can a stored procedure access tables?

26.4.12:

存储过程中是否有产生应用程序错误的语句呢?

Do stored procedures have a statement for raising

application errors?

26.4.13:

存储过程是否支持溢出处理?

Do stored procedures provide exception handling?

26.4.14:

MySQL 5.0能否返回存储过程的结果集?

Can MySQL 5.0 stored routines return result

sets?

26.4.15:

存储过程支持 WITH RECOMPILE 吗?

Is WITH RECOMPILE supported for stored

procedures?

26.4.16:

MySQL是否有类似 mod_plsql 的网关,使得Apache能直接调用数据库的存储过程?

Is there a MySQL equivalent to using

mod_plsql as a gateway on Apache to talk

directly to a stored procedure in the database?

26.4.17:

我能否向存储过程传递数组参数?

Can I pass an array as input to a stored procedure?

26.4.18:

我能否把一个游标作为存储过程的 IN (传入)参数?

Can I pass a cursor as an IN parameter to

a stored procedure?

26.4.19:

我能否把一个游标作为存储过程的 OUT (传出)参数?

Can I return a cursor as an OUT parameter

from a stored procedure?

26.4.20:

能否在存储过程中为了调试打印出某个变量的值?

Can I print out a variable's value within a stored procedure

for debugging purposes?

26.4.21:

能否在存储过程中提交一个的回滚事务?

Can I commit or roll back transactions inside a stored

procedure?

Questions and Answers

26.4.1:Does MySQL 5.0 support stored procedures?

是的.MySQL 5.0支持2中类型的存储例程 - 存储过程和存储函数.

Yes. MySQL 5.0 supports two types of stored

routines — stored procedures and stored functions.

26.4.2:Where can I find documentation for MySQL stored procedures

and stored functions?

26.4.3:Is there a discussion forum for MySQL stored procedures?

26.4.4:Where can I find the ANSI SQL 2003 specification for stored

procedures?

很抱歉,官方的规范还不是免费的(ANSI 对此是收费的).尽管如此,市面上有些书 - 如 Peter Gulutzan 和 Trudy Pelzer 所著的 SQL-99 Complete, Really,全面讲述了该标准,也包括存储过程.

Unfortunately, the official specifications are not freely

available (ANSI makes them available for purchase). However,

there are books — such as SQL-99 Complete,

Really by Peter Gulutzan and Trudy Pelzer

— which give a comprehensive overview of the standard,

including coverage of stored procedures.

26.4.5:How do you manage stored routines?

实践证明,存储例程中使用清晰的模式名很有用.管理存储过程可以使用语句 CREATE [FUNCTION|PROCEDURE], ALTER [FUNCTION|PROCEDURE, DROP [FUNCTION|PROCEDURE], 和 SHOW CREATE [FUNCTION|PROCEDURE].可以从数据库 INFORMATION_SCHEMA 的 ROUTINES 表中查看已经存在的存储过程的信息.详情请看 Section 20.14, “The INFORMATION_SCHEMA ROUTINES Table”.

It is always good practice to use a clear naming scheme for

your stored routines. You can manage stored procedures with

CREATE [FUNCTION|PROCEDURE],

ALTER [FUNCTION|PROCEDURE], DROP

[FUNCTION|PROCEDURE], and SHOW CREATE

[FUNCTION|PROCEDURE]. You can obtain information

about existing stored procedures using the

ROUTINES table in the

INFORMATION_SCHEMA database (see

Section 20.14, “The INFORMATION_SCHEMA ROUTINES Table”).

26.4.6:Is there a way to view all stored procedures and stored

functions in a given database?

是的.在INFORMATION_SCHEMA.ROUTINES 中使用以下语句就能查看 dbname 下所有的存储过程了.

SELECT ROUTINE_TYPE, ROUTINE_NAME

FROM INFORMATION_SCHEMA.ROUTINES

WHERE ROUTINE_SCHEMA='dbname';

存储例程的主体部分可以用语句 SHOW CREATE FUNCTION(适用于存储函数) 和 SHOW CREATE PROCEDURE(适用于存储过程) 来查看,详情请看 Section 13.5.4.5, “SHOW CREATE PROCEDURE 和 SHOW CREATE FUNCTION Syntax”.

Yes. For a database named dbname,

use this query on the

INFORMATION_SCHEMA.ROUTINES table:

SELECT ROUTINE_TYPE, ROUTINE_NAME

FROM INFORMATION_SCHEMA.ROUTINES

WHERE ROUTINE_SCHEMA='dbname';

The body of a stored routine can be viewed using

SHOW CREATE FUNCTION (for a stored

function) or SHOW CREATE PROCEDURE (for a

stored procedure). See

Section 13.5.4.5, “SHOW CREATE PROCEDURE and SHOW CREATE

FUNCTION Syntax”, for

more information.

26.4.7:Where are stored procedures stored?

在 mysql 系统数据库的 proc 表中.不过,不要直接访问系统数据库.相反地,使用语句 SHOW CREATE FUNCTION(适用于存储函数) 和 SHOW CREATE PROCEDURE(适用于存储过程) 来查看,详情请看 Section 13.5.4.5, “SHOW CREATE PROCEDURE 和 SHOW CREATE FUNCTION Syntax”.

In the proc table of the

mysql system database. However, you

should not access the tables in the system database

directly. Instead, use SHOW CREATE

FUNCTION to obtain information about stored

functions, and SHOW CREATE PROCEDURE to

obtain information about stored procedures. See

Section 13.5.4.5, “SHOW CREATE PROCEDURE and SHOW CREATE

FUNCTION Syntax”, for

more information about these statements.

You can also query the ROUTINES table in

the INFORMATION_SCHEMA database —

see Section 20.14, “The INFORMATION_SCHEMA ROUTINES Table”, for information about

this table.

26.4.8:Is it possible to group stored procedures or stored

functions into packages?

不.MySQL 5.0不支持

No. This is not supported in MySQL 5.0.

26.4.9:Can a stored procedure call another stored procedure?

是的

Yes.

26.4.10:Can a stored procedure call a trigger?

存储过程中可以执行一条SQL语句,例如 UPDATE 语句,这就会导致触发器起作用.

A stored procedure can execute an SQL statement, such as an

UPDATE, that causes a trigger to fire.

26.4.11:Can a stored procedure access tables?

是的.存储过程可根据需要访问一个或多个表.

Yes. A stored procedure can access one or more tables as

required.

26.4.12:Do stored procedures have a statement for raising

application errors?

MySQL 5.0还不行,我们正打算在将来的MySQL发行版中实现标准SQL中的 SIGNAL 和 RESIGNAL 语句.

Not in MySQL 5.0. We intend to implement the

SQL standard SIGNAL and

RESIGNAL statements in a future MySQL

release.

26.4.13:Do stored procedures provide exception handling?

MySQL 根据SQL标准实现了 HANDLER 定义.详情请看 Section 17.2.8.2, “DECLARE Handlers”, for.

MySQL implements HANDLER definitions

according to the SQL standard. See

Section 17.2.8.2, “DECLARE Handlers”, for

details.

26.4.14:Can MySQL 5.0 stored routines return result

sets?

是的.如果你在存储过程或存储函数中执行一条普通的 SELECT 语句,那么结果集会直接返回给客户端.需要使用MySQL 4.1的客户端-服务器协议来支持它,这意味着 - 例如在PHP中,就需要用 mysqli 扩展而非 mysql 扩展才能实现.

Yes. If you perform an ordinary SELECT

inside a stored procedure or stored function, the result set

is returned directly to the client. You need to use the

MySQL 4.1 client-server protocol for this to work. This

means that — for instance — in PHP, you need to

use the mysqli extension rather than the

old mysql extension.

26.4.15:Is WITH RECOMPILE supported for stored

procedures?

MySQL 5.0还不支持.

Not in MySQL 5.0.

26.4.16:Is there a MySQL equivalent to using

mod_plsql as a gateway on Apache to talk

directly to a stored procedure in the database?

MySQL 5.0还不没有.

There is no equivalent in MySQL 5.0.

26.4.17:Can I pass an array as input to a stored procedure?

MySQL 5.0还不支持.

Not in MySQL 5.0.

26.4.18:Can I pass a cursor as an IN parameter to

a stored procedure?

在MySQL 5.0中,游标只能使用在存储过程中.

In MySQL 5.0, cursors are available inside

stored procedures only.

26.4.19:Can I return a cursor as an OUT parameter

from a stored procedure?

在MySQL 5.0中,游标只能使用在存储过程中.不过,如果你在 SELECT 语句中如果没有打开游标的话,那么结果集会被直接发送给客户端,也可以 SELECT INTO 到变量中.详情请看 Section 13.2.7, “SELECT Syntax”.

In MySQL 5.0, cursors are available inside

stored procedures only. However, if you do not open a cursor

on a SELECT, the result will be sent

directly to the client. You can also SELECT

INTO variables. See Section 13.2.7, “SELECT Syntax”.

26.4.20:Can I print out a variable's value within a stored procedure

for debugging purposes?

是的.如果你在存储过程或存储函数中执行一条普通的 SELECT 语句,那么结果集会直接返回给客户端.需要使用MySQL 4.1的客户端-服务器协议来支持它,这意味着 - 例如在PHP中,就需要用 mysqli 扩展而非 mysql 扩展才能实现.

Yes. If you perform an ordinary SELECT

inside a stored procedure or stored function, the result set

is returned directly to the client. You will need to use the

MySQL 4.1 client-server protocol for this to work. This

means that — for instance — in PHP, you need to

use the mysqli extension rather than the

old mysql extension.

26.4.21:Can I commit or roll back transactions inside a stored

procedure?

是的.不过不能在存储函数中执行事务性操作.

Yes. However, you cannot perform transactional operations

within a stored function.

mysql 存储过程 compile_存储过程 | iMySQL | 老叶茶馆相关推荐

  1. php调用mysql存储过程报错,php | iMySQL | 老叶茶馆

    用PHP控制您的浏览器cache Output Control 函数可以让你自由控制脚本中数据的输出.它非常地有用,特别是对于:当你想在数据已经输出后,再输出文件头的情况.输出控制函数不对使用 hea ...

  2. 『老叶茶馆』2021年度热文推荐

    下面是『老叶茶馆』微信公众号2021年度热文列表,按时间先后顺序列出.有几篇文章值得多次回味,请各位读者们查收. MySQL SQL优化的正确姿势 MySQL数据库CPU问题一则 count 浅析 云 ...

  3. 【老叶茶馆】MySQL复制中slave延迟监控

    转自:http://imysql.com/2014/08/30/mysql-faq-howto-monitor-slave-lag.shtml#comment-146 [MySQL FAQ]系列 - ...

  4. mysql老叶博客_MySQL binlog后面的编号最大是多大?【老叶茶馆公众号】

    MySQL binlog后面的编号最大是多大? 具体文章请关注微信公众号:izhishuedu [知数堂] 知数堂版权所有. 这里我就不啰嗦了,直接上贴代码: 版本:5.7.18 mysql-5.7. ...

  5. MySQL binlog后面的编号最大是多大?【老叶茶馆公众号】

    MySQL binlog后面的编号最大是多大? 原文地址:http://mp.weixin.qq.com/s/gDpWhlBawRal_pQK2huTMA 具体文章请关注微信公众号:izhishued ...

  6. [转发] 老叶观点:MySQL开发规范之我见

    原文: http://imysql.com/2015/07/23/something-important-about-mysql-design-reference.shtml 老叶观点:MySQL开发 ...

  7. 老叶 mysql_老叶观点:MySQL开发规范之我见

    大多数MySQL规范在网上也都能找得到相关的分享,在这里要分享的是老叶个人认为比较重要的,或者容易被忽视的,以及容易被混淆的一些地方. 1.默认使用InnoDB引擎 [老叶观点]已多次呼吁过了,Inn ...

  8. 老叶倡议:MySQL压力测试基准值

    通常,我们会出于以下几个目的对MySQL进行压力测试: 1.确认新的MySQL版本性能相比之前差异多大,比如从5.6变成5.7,或者从官方版本改成Percona分支版本: 2.确认新的服务器性能是否更 ...

  9. 系列 | 高性能存储-MySQL数据库之存储过程揭秘

    墨墨导读:本文介绍什么是存储过程?为什么要使用存储过程?如何使用存储过程?如何去使用存储过程以及怎么执行存储过程. DBASK小程序已经开设"MySQL 数据库专栏",欢迎大家关注 ...

最新文章

  1. Unity3D 中 2D_Toolkit插件下载 和 导入方法
  2. RHEL5一个网卡绑定多个IP
  3. iphone闪退修复工具_苹果中国回应iPhone致命漏洞:不予置评
  4. eclipse忘记了程序保存在哪里怎么办
  5. 字符串转换为整数的源码atoi()
  6. hadoop05---进程线程
  7. 国网376.1协议报文地址域
  8. 灵悟礼品网上专卖店——画出项目的主要框架
  9. 微信开发工具调试窗口怎样查看netWork
  10. 规模再创新高!新能源汽车蓝海谁主沉浮
  11. icloud 照片同步_如何确保Mac和iPhone的照片同步到iCloud
  12. 服务器不能用pe安装win7系统安装,使用PE安装win7系统失败了怎么办
  13. 图文推荐系统之数据冷启小结
  14. 计算机维修志愿活动策划书,“义务维修,温暖校园”志愿服务活动策划书
  15. Python-Flask-2023.1.22
  16. 中国土地市场网landchina.com数据采集心得
  17. 简单学习Java中的抽象语法树(AST)
  18. stm32驱动ht1621仪表盘显示
  19. php判断图片有没有ps过,鉴别P图,如何鉴别图片是否被P过
  20. 打印倒三角形——固定行数与键盘输入行数

热门文章

  1. storm大数据视频教程全集下载
  2. django图书管理系统:
  3. win7计算机无法显示,最新版本:如果无法显示win7计算机的图片预览,该怎么办...
  4. java计算机毕业设计vue校园菜鸟驿站管理系统源码+数据库+系统+lw文档
  5. vue项目中使用阿里巴巴矢量图库图标的操作步骤
  6. Android基于卷积神经网络的数字手势识别识别数字手势0-10 Android studio编译
  7. vivo X20全面屏手机推出黑金旗舰版,这个十月神秘无限
  8. ev录屏嵌入摄像头花屏问题
  9. cookie setSecure详解
  10. C++的lib文件到底是什么