Mysql
 SQL >> Datenbank >  >> RDS >> Mysql

Mehrere semikolongetrennte Queries mit MySQL Prepared Statements ausführen

Nein, PREPARE / EXECUTE führt nur eine Anweisung pro Aufruf aus.

Sie können aber eine Hilfsprozedur verwenden:

CREATE PROCEDURE exec_qry(p_sql VARCHAR(1000))
BEGIN
    SET @tquery = p_sql;
    PREPARE stmt FROM @tquery;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
END

Aufruf:

CALL exec_qry('CREATE TABLE t2 AS SELECT * FROM test');
CALL exec_qry('SELECT * FROM t2');
CALL exec_qry('DROP TABLE t2');