Skip to content

PREPARE

PREPARE stmt1 FROM 'SELECT * FROM table WHERE column = ?';
SET @var = 'value';
EXECUTE stmt1 USING @var;
+--------+---------+
| column1 | column2 |
+--------+---------+
| row1 | row2 |
+--------+---------+

In the example code, PREPARE statement is used to prepare the SQL statement ‘SELECT * FROM table WHERE column = ?’. The ? acts as a placeholder. Then, using the SET command, a value ‘value’ is assigned to @var. Finally, the EXECUTE statement is used to execute the prepared statement, substituting the placeholder with @var. The output shows the resultant table after executing the prepared SQL statement.