# Programmatic & Compound Statements

- [BEGIN END](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/begin-end.md): Group multiple SQL statements into a logical block. This construct defines a compound statement, creating a new scope for variables and exception handling.
- [CASE Statement](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/case-statement.md): Complete reference for CASE Statement in MariaDB. Complete syntax guide with all options, clauses, and practical examples with comprehensive examples and.
- [DECLARE CONDITION](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/declare-condition.md): Define named error conditions. This statement associates a name with a specific SQLSTATE or MariaDB error code for easier handling in stored programs.
- [DECLARE HANDLER](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/declare-handler.md): Specify actions for error conditions. This statement defines handler routines (CONTINUE or EXIT) to manage exceptions or warnings within a block.
- [DECLARE TYPE](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/declare-type.md): Define data types for Oracle compatibility. This statement allows declaring PL/SQL-style record types and associative arrays, and REF CURSOR types within stored procedures.
- [DECLARE Variable](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/declare-variable.md): Initialize local variables within a stored program. This statement defines variables with a specific data type and optional default value.
- [FOR](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/for.md): Loop through a range or cursor result set. This control flow statement repeatedly executes a block of code for each item in a specified range or query.
- [GOTO](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/goto.md): Jump to a labeled point in the code. This Oracle-compatible statement transfers execution control to a specific label within the stored program.
- [IF](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/if.md): Execute code based on conditions. This control flow statement runs different blocks of SQL statements depending on whether a specified condition is true.
- [ITERATE](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/iterate.md): Restart the current loop. This statement jumps back to the beginning of a LOOP, REPEAT, or WHILE block, skipping any remaining statements in the current iteration.
- [Labels](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/labels.md): Identify blocks and loops for flow control. Labels provide names for BEGIN...END blocks or loops, allowing them to be targeted by LEAVE, ITERATE, or GOTO statements.
- [LEAVE](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/leave.md): Exit a labeled block or loop immediately. This statement terminates the execution of the current loop or compound statement and continues after the block.
- [LOOP](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/loop.md): Create a simple loop construct. This statement repeatedly executes a block of code until explicitly terminated by a LEAVE statement.
- [REPEAT LOOP](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/repeat-loop.md): Execute a block until a condition is met. This loop construct runs at least once and continues repeating as long as the UNTIL condition remains false.
- [RESIGNAL](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/resignal.md): Propagate error conditions. This statement allows a handler to pass an error condition back to the caller or modify the error information before passing it on.
- [RETURN](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/return.md): Exit a stored function and return a value. This statement terminates function execution and sends the specified result back to the caller.
- [SELECT INTO](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/selectinto.md): Assign query results to variables. This statement retrieves column values from a single row and stores them in local variables or user-defined variables.
- [SIGNAL](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/signal.md): Raise a custom error condition. This statement allows stored programs to generate specific error messages and SQLSTATEs to handle application logic exceptions.
- [WHILE](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/while.md): Execute a block while a condition is true. This loop construct checks a condition before each iteration and repeats the block as long as the condition holds.
- [Using Compound Statements Outside of Stored Programs](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/using-compound-statements-outside-of-stored-programs.md)
- [Cursors](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors.md): Learn about cursors in MariaDB Server's programmatic compound statements. This section details how to iterate over result sets row-by-row within stored procedures and functions.
- [Cursor Overview](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/cursor-overview.md)
- [CLOSE](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/close.md)
- [DECLARE CURSOR](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/declare-cursor.md)
- [FETCH](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/fetch.md)
- [OPEN](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/open.md)
- [Diagnostics](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-diagnostics.md): Learn about diagnostics in programmatic compound statements. This section covers error handling and information retrieval within stored procedures and functions for effective debugging.
- [Diagnostics Area](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-diagnostics/diagnostics-area.md)
- [GET DIAGNOSTICS](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-diagnostics/get-diagnostics.md)
- [SQLSTATE](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-diagnostics/sqlstate.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
