> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/server-usage/stored-routines/stored-routine-limitations.md).

# Stored Routine Limitations

Stored routines have specific restrictions, such as prohibiting certain SQL statements (e.g., LOAD DATA) and disallowing result sets in functions.

The following SQL statements are not permitted inside any [stored routines](/docs/server/server-usage/stored-routines.md) ([stored functions](/docs/server/server-usage/stored-routines/stored-functions.md), [stored procedures](/docs/server/server-usage/stored-routines/stored-procedures.md), [events](/docs/server/server-usage/triggers-events/event-scheduler/events.md) or [triggers](/docs/server/server-usage/triggers-events/triggers.md)).

* [ALTER VIEW](/docs/server/server-usage/views/alter-view.md); you can use [CREATE OR REPLACE VIEW](/docs/server/server-usage/views/create-view.md) instead.
* [LOAD DATA](/docs/server/reference/sql-statements/data-manipulation/inserting-loading-data/load-data-into-tables-or-index/load-data-infile.md) and [LOAD TABLE](/docs/server/ha-and-performance/standard-replication.md).
* [CHANGE MASTER TO](/docs/server/reference/sql-statements/administrative-sql-statements/replication-statements/change-master-to.md)
* [INSERT DELAYED](/docs/server/reference/sql-statements/data-manipulation/inserting-loading-data/insert-delayed.md) is permitted, but the statement is handled as a regular [INSERT](/docs/server/reference/sql-statements/data-manipulation/inserting-loading-data/insert.md).
* [LOCK TABLES](/docs/server/reference/sql-statements/transactions/lock-tables.md) and [UNLOCK TABLES](/docs/server/reference/sql-statements/transactions/lock-tables.md).
* References to [local variables](/docs/server/reference/sql-statements/programmatic-compound-statements/declare-variable.md) within prepared statements inside a stored routine (use [user-defined variables](/docs/server/reference/sql-structure/sql-language-structure/user-defined-variables.md) instead).
* [BEGIN (WORK)](/docs/server/reference/sql-statements/transactions/start-transaction.md) is treated as the beginning of a [BEGIN END](/docs/server/reference/sql-statements/programmatic-compound-statements/begin-end.md) block, not a transaction, so [START TRANSACTION](/docs/server/reference/sql-statements/transactions/start-transaction.md) needs to be used instead.
* The number of permitted recursive calls is limited to [max\_sp\_recursion\_depth](/docs/server/server-management/variables-and-modes/server-system-variables.md#max_sp_recursion_depth). If this variable is 0 (default), recursivity is disabled. The limit does not apply to stored functions.
* Most statements that are not permitted in prepared statements are not permitted in stored programs. See [Prepare Statement:Permitted statements](/docs/server/reference/sql-statements/prepared-statements/prepare-statement.md#permitted-statements) for a list of statements that can be used. [SIGNAL](/docs/server/reference/sql-statements/programmatic-compound-statements/signal.md), [RESIGNAL](/docs/server/reference/sql-statements/programmatic-compound-statements/resignal.md) and [GET DIAGNOSTICS](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-diagnostics/get-diagnostics.md) are exceptions, and may be used in stored routines.

There are also further limitations specific to the kind of stored routine.

Note that, if a stored program calls another stored program, the latter will inherit the caller's limitations. So, for example, if a stored procedure is called by a stored function, that stored procedure will not be able to produce a result set, because stored functions can't do this.

## See Also

* [Stored Function Limitations](/docs/server/server-usage/stored-routines/stored-functions/stored-function-limitations.md)
* [Trigger Limitations](/docs/server/server-usage/triggers-events/triggers/trigger-limitations.md)
* [Event Limitations](/docs/server/server-usage/triggers-events/event-scheduler/event-limitations.md)

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}
