- A.4.1. MySQL 支持存储过程和函数吗? A.4.1. Does MySQL support stored procedures and functions?
- A.4.2. 我在哪里可以找到 MySQL 存储过程和存储函数的文档? A.4.2. Where can I find documentation for MySQL stored procedures and stored functions?
- A.4.3. 有没有关于 MySQL 存储过程的讨论论坛? A.4.3. Is there a discussion forum for MySQL stored procedures?
- A.4.4. 我在哪里可以找到存储过程的 ANSI SQL 2003 规范? A.4.4. Where can I find the ANSI SQL 2003 specification for stored procedures?
- A.4.5. 如何管理存储例程? A.4.5. How do you manage stored routines?
- A.4.6. 是否有方法查看给定数据库中的所有存储过程和存储函数? A.4.6. Is there a way to view all stored procedures and stored functions in a given database?
- A.4.7. 存储过程存储在哪里? A.4.7. Where are stored procedures stored?
- A.4.8. 是否可以将存储过程或存储函数分组到包中? A.4.8. Is it possible to group stored procedures or stored functions into packages?
- A.4.9. 存储过程可以调用另一个存储过程吗? A.4.9. Can a stored procedure call another stored procedure?
- A.4.10. 存储过程可以调用触发器吗? A.4.10. Can a stored procedure call a trigger?
- A.4.11. 存储过程可以访问表吗? A.4.11. Can a stored procedure access tables?
- A.4.12. 存储过程是否有用于引发应用程序错误的语句? A.4.12. Do stored procedures have a statement for raising application errors?
- A.4.13. 存储过程是否提供异常处理? A.4.13. Do stored procedures provide exception handling?
- A.4.14. MySQL 存储例程可以返回结果集吗? A.4.14. Can MySQL stored routines return result sets?
- A.4.15. 存储过程是否支持 WITH RECOMPILE? A.4.15. Is WITH RECOMPILE supported for stored procedures?
- A.4.16. 有没有 MySQL 等效方法使用 mod_plsql 作为 Apache 网关直接与数据库中的存储过程通信? A.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?
- A.4.17. 我可以将数组作为输入传递给存储过程吗? A.4.17. Can I pass an array as input to a stored procedure?
- A.4.18. 我可以将游标作为 IN 参数传递给存储过程吗? A.4.18. Can I pass a cursor as an IN parameter to a stored procedure?
- A.4.19. 我可以将游标作为 OUT 参数从存储过程中返回吗? A.4.19. Can I return a cursor as an OUT parameter from a stored procedure?
- A.4.20. 我可以在存储例程中打印变量值以用于调试吗? A.4.20. Can I print out a variable's value within a stored routine for debugging purposes?
- A.4.21. 我可以在存储过程中提交或回滚事务吗? A.4.21. Can I commit or roll back transactions inside a stored procedure?
- A.4.22. MySQL 存储过程和函数可以与复制一起使用吗? A.4.22. Do MySQL stored procedures and functions work with replication?
- A.4.23. 在复制源服务器上创建的存储过程和函数会被复制到副本服务器吗? A.4.23. Are stored procedures and functions created on a replication source server replicated to a replica?
- A.4.24. 存储过程和函数中发生的操作是如何被复制的? A.4.24. How are actions that take place inside stored procedures and functions replicated?
- A.4.25. 在将存储过程和函数与复制一起使用时是否有特殊的安全要求? A.4.25. Are there special security requirements for using stored procedures and functions together with replication?
- A.4.26. 复制存储过程和函数的操作存在哪些限制? A.4.26. What limitations exist for replicating stored procedure and function actions?
- A.4.27. 前述限制是否会影响 MySQL 执行时间点恢复的能力? A.4.27. Do the preceding limitations affect the ability of MySQL to do point-in-time recovery?
- A.4.28. 正在采取什么措施来纠正上述限制? A.4.28. What is being done to correct the aforementioned limitations?
A.4.1. | MySQL 支持存储过程和函数吗?Does MySQL support stored procedures and functions? |
是的。MySQL 支持两种类型的存储例程:存储过程和存储函数。Yes. MySQL supports two types of stored routines, stored procedures, and stored functions. | |
A.4.2. | 我在哪里可以找到 MySQL 存储过程和存储函数的文档?Where can I find documentation for MySQL stored procedures and stored functions? |
请参阅 第 27.2 节,“使用存储例程”。See Section 27.2, “Using Stored Routines”. | |
A.4.3. | MySQL 存储过程有讨论论坛吗?Is there a discussion forum for MySQL stored procedures? |
有的。请参阅 https://forums.mysql.com/list.php?98。Yes. See https://forums.mysql.com/list.php?98. | |
A.4.4. | 我在哪里可以找到存储过程的 ANSI SQL 2003 规范?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, that provide a comprehensive overview of the standard, including coverage of stored procedures. | |
A.4.5. | 你如何管理存储程序?How do you manage stored routines? |
为你的存储例程使用清晰的命名方案始终是一个好习惯。你可以使用 | |
A.4.6. | 是否有办法查看给定数据库中的所有存储过程和存储函数?Is there a way to view all stored procedures and stored functions in a given database? |
是的。对于名为 SELECT ROUTINE_TYPE, ROUTINE_NAME
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_SCHEMA='有关更多信息,请参见第 28.3.30 节,“INFORMATION_SCHEMA.ROUTINES 表”。For more information, see Section 28.3.30, “The INFORMATION_SCHEMA ROUTINES Table”. 可以使用 | |
A.4.7. | 存储过程存储在哪里?Where are stored procedures stored? |
存储过程存储在 您也可以使用 | |
A.4.8. | 是否可以将存储过程或存储函数分组到包中?Is it possible to group stored procedures or stored functions into packages? |
不可以。MySQL 不支持此功能。No. This is not supported in MySQL. | |
A.4.9. | 存储过程可以调用另一个存储过程吗?Can a stored procedure call another stored procedure? |
可以。Yes. | |
A.4.10. | 存储过程可以调用触发器吗?Can a stored procedure call a trigger? |
存储过程可以执行 SQL 语句,例如 | |
A.4.11. | 存储过程可以访问表吗?Can a stored procedure access tables? |
可以。存储过程可以根据需要访问一个或多个表。Yes. A stored procedure can access one or more tables as required. | |
A.4.12. | 存储过程是否有用于引发应用程序错误的语句?Do stored procedures have a statement for raising application errors? |
可以。MySQL 实现了 SQL 标准的 | |
A.4.13. | 存储过程提供异常处理吗?Do stored procedures provide exception handling? |
MySQL 根据 SQL 标准实现了 | |
A.4.14. | MySQL 存储例程可以返回结果集吗?Can MySQL stored routines return result sets? |
存储过程可以这样做,但存储函数不行。如果在存储过程中执行普通的 | |
A.4.15. | 存储过程支持 |
没有。No. | |
A.4.16. | MySQL 是否有类似使用 |
MySQL 中没有相应的等效功能。There is no equivalent in MySQL. | |
A.4.17. | 我可以将数组作为输入传递给存储过程吗?Can I pass an array as input to a stored procedure? |
没有。No. | |
A.4.18. | 我可以将游标作为 |
游标只能在存储过程中使用。Cursors are only available inside stored procedures. | |
A.4.19. | 我可以将游标作为 |
Cursors are only available inside stored procedures. However, if
you do not open a cursor on a
| |
A.4.20. | 我可以在存储例程中打印变量的值以进行调试吗?Can I print out a variable's value within a stored routine for debugging purposes? |
是的,你可以在存储过程中执行此操作,但不能在存储函数中执行。如果你在存储过程中执行普通的 | |
A.4.21. | 我可以在存储过程中提交或回滚事务吗?Can I commit or roll back transactions inside a stored procedure? |
可以。然而,你不能在存储函数中执行事务操作。Yes. However, you cannot perform transactional operations within a stored function. | |
A.4.22. | MySQL 存储过程和函数可以与复制一起使用吗?Do MySQL stored procedures and functions work with replication? |
是的,通过存储过程和函数执行的标准操作会从复制源服务器复制到副本。有关一些限制的详细描述,请参见第 27.7 节,“存储程序二进制日志记录”。Yes, standard actions carried out in stored procedures and functions are replicated from a replication source server to a replica. There are a few limitations that are described in detail in Section 27.7, “Stored Program Binary Logging”. | |
A.4.23. | 在复制源服务器上创建的存储过程和函数会复制到副本吗?Are stored procedures and functions created on a replication source server replicated to a replica? |
是的,通过正常的 DDL 语句在复制源服务器上创建的存储过程和函数会复制到副本,使这些对象在两台服务器上都存在。对存储过程和函数的 | |
A.4.24. | 在存储过程和函数中发生的操作是如何被复制的?How are actions that take place inside stored procedures and functions replicated? |
MySQL 会记录存储过程中的每个 DML 事件,并将这些单独的操作复制到副本。实际用于执行存储过程的调用不会被复制。MySQL records each DML event that occurs in a stored procedure and replicates those individual actions to a replica. The actual calls made to execute stored procedures are not replicated. 更改数据的存储函数会作为函数调用进行记录,而不是记录函数内部发生的 DML 事件。Stored functions that change data are logged as function invocations, not as the DML events that occur inside each function. | |
A.4.25. | 在将存储过程和函数与复制一起使用时,有特殊的安全要求吗?Are there special security requirements for using stored procedures and functions together with replication? |
是的。因为副本有权限执行从源的二进制日志中读取的任何语句,所以在将存储函数用于复制时存在特殊的安全限制。如果复制或二进制日志记录(用于时间点恢复的目的)处于活动状态,那么 MySQL DBA 有两种安全选项可供选择:Yes. Because a replica has authority to execute any statement read from a source's binary log, special security constraints exist for using stored functions with replication. If replication or binary logging in general (for the purpose of point-in-time recovery) is active, then MySQL DBAs have two security options open to them:
| |
A.4.26. | 在复制存储过程和函数的操作时存在哪些限制?What limitations exist for replicating stored procedure and function actions? |
存储过程中嵌入的非确定性(随机)或基于时间的操作可能无法正确复制。由于其本质,随机生成的结果不可预测,也无法完全重现;因此,复制到副本的随机操作不会反映在源上执行的操作。将存储函数声明为 此外,基于时间的操作无法在副本上重现,因为存储过程中此类操作的时间无法通过用于复制的二进制日志再现。二进制日志仅记录 DML 事件,并不考虑时间约束。In addition, time-based actions cannot be reproduced on a replica because the timing of such actions in a stored procedure is not reproducible through the binary log used for replication. It records only DML events and does not factor in timing constraints. 最后,在大规模 DML 操作(例如批量插入)期间发生错误的非事务表可能会出现复制问题,即源可能会部分更新 DML 活动,但由于发生错误,副本没有进行更新。一种解决方法是使用 | |
A.4.27. | 上述限制是否影响 MySQL 执行时间点恢复的能力?Do the preceding limitations affect the ability of MySQL to do point-in-time recovery? |
影响复制的相同限制也会影响时间点恢复。The same limitations that affect replication do affect point-in-time recovery. | |
A.4.28. | 为纠正上述限制正在做什么?What is being done to correct the aforementioned limitations? |
您可以选择基于语句的复制或基于行的复制。最初的复制实现是基于语句的二进制日志。基于行的二进制日志解决了前面提到的限制。You can choose either statement-based replication or row-based replication. The original replication implementation is based on statement-based binary logging. Row-based binary logging resolves the limitations mentioned earlier. 混合复制也可用(通过使用 更多信息,请参见 第 19.2.1 节,“复制格式”。For additional information, see Section 19.2.1, “Replication Formats”. |