Rechercher dans le manuel MySQL
A.4 MySQL 8.0 FAQ: Stored Procedures and Functions
- A.4.1. Does MySQL 8.0 support stored procedures and functions?
- A.4.2. Where can I find documentation for MySQL stored procedures and stored functions?
- A.4.3. Is there a discussion forum for MySQL stored procedures?
- A.4.4. Where can I find the ANSI SQL 2003 specification for 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?
- A.4.7. Where are stored procedures stored?
- A.4.8. Is it possible to group stored procedures or stored functions into packages?
- A.4.9. Can a stored procedure call another stored procedure?
- A.4.10. Can a stored procedure call a trigger?
- A.4.11. Can a stored procedure access tables?
- A.4.12. Do stored procedures have a statement for raising application errors?
- A.4.13. Do stored procedures provide exception handling?
- A.4.14. Can MySQL 8.0 stored routines return result sets?
- A.4.15. Is WITH RECOMPILE supported for stored procedures?
- 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. Can I pass an array as input to a stored procedure?
- A.4.18. Can I pass a cursor as an IN parameter to a stored procedure?
- A.4.19. Can I return a cursor as an OUT parameter from a stored procedure?
- 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?
- A.4.22. Do MySQL 8.0 stored procedures and functions work with replication?
- A.4.23. Are stored procedures and functions created on a master server replicated to a slave?
- A.4.24. How are actions that take place inside stored procedures and functions replicated?
- A.4.25. Are there special security requirements for using stored procedures and functions together with replication?
- A.4.26. What limitations exist for replicating stored procedure and function actions?
- A.4.27. Do the preceding limitations affect the ability of MySQL to do point-in-time recovery?
- A.4.28. What is being done to correct the aforementioned limitations?
A.4.1. | Does MySQL 8.0 support stored procedures and functions? |
Yes. MySQL 8.0 supports two types of stored routines, stored procedures and stored functions. | |
A.4.2. | Where can I find documentation for MySQL stored procedures and stored functions? |
A.4.3. | Is there a discussion forum for MySQL stored procedures? |
Yes. See https://forums.mysql.com/list.php?98. | |
A.4.4. | Where can I find the ANSI SQL 2003 specification for stored procedures? |
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? |
It is always good practice to use a clear naming scheme for your
stored routines. You can manage stored procedures with
| |
A.4.6. | Is there a way to view all stored procedures and stored functions in a given database? |
Yes. For a database named For more information, see Section 25.23, “The INFORMATION_SCHEMA ROUTINES Table”.
The body of a stored routine can be viewed using
| |
A.4.7. | Where are stored procedures stored? |
Stored procedures are stored in the
You can also use | |
A.4.8. | Is it possible to group stored procedures or stored functions into packages? |
No. This is not supported in MySQL 8.0. | |
A.4.9. | Can a stored procedure call another stored procedure? |
Yes. | |
A.4.10. | Can a stored procedure call a trigger? |
A stored procedure can execute an SQL statement, such as an
| |
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? |
Yes. MySQL 8.0 implements the SQL standard
| |
A.4.13. | Do stored procedures provide exception handling? |
MySQL implements | |
A.4.14. | Can MySQL 8.0 stored routines return result sets? |
Stored procedures can, but stored functions
cannot. If you perform an ordinary
| |
A.4.15. |
Is |
Not in MySQL 8.0. | |
A.4.16. |
Is there a MySQL equivalent to using
|
There is no equivalent in MySQL 8.0. | |
A.4.17. | Can I pass an array as input to a stored procedure? |
Not in MySQL 8.0. | |
A.4.18. |
Can I pass a cursor as an |
In MySQL 8.0, cursors are available inside stored procedures only. | |
A.4.19. |
Can I return a cursor as an |
In MySQL 8.0, cursors are available inside stored
procedures only. 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? |
Yes, you can do this in a stored procedure,
but not in a stored function. If you perform an ordinary
| |
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. | Do MySQL 8.0 stored procedures and functions work with replication? |
Yes, standard actions carried out in stored procedures and functions are replicated from a master MySQL server to a slave server. There are a few limitations that are described in detail in Section 24.7, “Stored Program Binary Logging”. | |
A.4.23. | Are stored procedures and functions created on a master server replicated to a slave? |
Yes, creation of stored procedures and functions carried out
through normal DDL statements on a master server are replicated
to a slave, so the objects will exist on both servers.
| |
A.4.24. | How are actions that take place inside stored procedures and functions replicated? |
MySQL records each DML event that occurs in a stored procedure and replicates those individual actions to a slave server. The actual calls made to execute stored procedures are not replicated. 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? |
Yes. Because a slave server has authority to execute any statement read from a master'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? |
Nondeterministic (random) or time-based actions embedded in
stored procedures may not replicate properly. By their very
nature, randomly produced results are not predictable and cannot
be exactly reproduced, and therefore, random actions replicated
to a slave will not mirror those performed on a master.
Declaring stored functions to be
In addition, time-based actions cannot be reproduced on a slave 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.
Finally, nontransactional tables for which errors occur during
large DML actions (such as bulk inserts) may experience
replication issues in that a master may be partially updated
from DML activity, but no updates are done to the slave because
of the errors that occurred. A workaround is for a function's
DML actions to be carried out with the | |
A.4.27. | 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.
Mixed replication is also
available (by starting the server with
For additional information, see Section 17.2.1, “Replication Formats”. |
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-faqs-stored-procs.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.