Bug #76689 In PREPARED STATEMENTS impossible to use multiple statements
Submitted: 14 Apr 2015 14:24 Modified: 27 Apr 2015 4:25
Reporter: Mikhail Gavrilov Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S4 (Feature request)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: PREPARE multiple statements

[14 Apr 2015 14:24] Mikhail Gavrilov
Description:
In PREPARED STATEMENTS impossible to use multiple statements

How to repeat:
Example:

DELIMITER $$

CREATE PROCEDURE `test_dsql`()
BEGIN
	PREPARE sql_fn FROM 'select 1; select 2';
	EXECUTE sql_fn;
	DEALLOCATE PREPARE sql_fn;
END$$

DELIMITER ;

Query: call test_dsql()

Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select 2' at line 1
[14 Apr 2015 16:40] MySQL Verification Team
Hi Mikhail,

This is expected behavior. If you look at documentation wrt prepared statement:

https://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.html
https://dev.mysql.com/doc/refman/5.5/en/sql-syntax-prepared-statements.html
https://dev.mysql.com/doc/refman/5.6/en/sql-syntax-prepared-statements.html
https://dev.mysql.com/doc/refman/5.7/en/sql-syntax-prepared-statements.html

You can find that 

[quote]
SQL syntax for prepared statements does not support multi-statements (that is, multiple statements within a single string separated by “;” characters). 
[/quote]

all best
Bogdan Kecman
[14 Apr 2015 17:21] Mikhail Gavrilov
Bogdan, maybe better to re-register as a feature request.
[2 Mar 2016 18:04] terjyej rtjnsfgjsf
Consider a stored procedure for automatic generation of triggers with IF.
Without this feature it is impossible to automatically apply the generated trigger.
[23 Jul 2021 13:17] MySQL Verification Team
Bug #104391 marked as duplicate of this one.