Somebody asked about the possibility of putting DML statements
inside MySQL stored functions. DML statements like the
INSERT
, UPDATE
, and
DELETE
. When I said, “Yes, you can put DML
statements inside functions.” They showed me the error they
encountered, which is only raised at compilation when you put an
explicit COMMIT
statement or a Data
Definition Language (DDL) statement (CREATE
,
ALTER
, DROP
, or RENAME
)
inside a MySQL function. The actual error message displayed is:
ERROR 1422 (HY000): Explicit OR implicit commit IS NOT allowed IN stored FUNCTION OR TRIGGER.
While an explicit COMMIT
is obvious when placed
inside a function, the implicit COMMIT
statement
isn’t obvious unless you know a DDL statement generates one. This
means you can’t include any DDL statement inside a stored …