I am building a \"bank\" as an assignment for a database course I am taking. I have created a stored function which takes a few IN
variables, such as account ID
There are a number of statements that cause an implicit commit, and none of these can be used inside a stored function or a trigger, or in a stored procedure that is called from a stored function or trigger, because that is not really any different in its net effect.
A moment's reflection explains the reason for this: stored functions (and triggers) execute while a query is running. They always, without exception, begin executing after the query starts, and finish executing before the query finishes. They can also run multiple times during the execution of a single query, particularly when the query involves multiple rows.
In that light, it would not make sense if it were possible to COMMIT
a transaction while a single query is running... and that's what START TRANSACTION
does, if a transaction is running -- it implicitly commits the current transaction, and starts a new one.
This is fine in a stored procedure, as long as you're not calling it in the middle of another query (via a stored function or trigger, which is the only way to invoke a procedure in the middle of another query) but doing what you are doing here is not supported... even if there's not a transaction running, it still isn't possible to start a transaction in the middle of a running query.
http://dev.mysql.com/doc/refman/5.6/en/implicit-commit.html