0

I am trying to store table results of two stored procedures to a single table in phpmyadmin routine window which gives me mariadb syntax error. Calling the stored procedures separately gives me the results.

Stored procedure code

BEGIN
CREATE TABLE temp(Name VARCHAR(200), Value1 varchar(100), Value2 varchar(100))
INSERT INTO temp CALL stored_procedure1();
INSERT INTO temp CALL stored_procedure2();
END

This code gives me the following syntax error

The following query has failed:

"CREATE DEFINER=`root`@`localhost` PROCEDURE `get_data`() NOT DETERMINISTIC NO SQL SQL SECURITY DEFINER BEGIN CREATE TABLE temp(Name VARCHAR(200), Value1 varchar(100), Value2 varchar(100)) INSERT INTO temp CALL stored_procedure1(); INSERT INTO temp CALL stored_procedure2(); END"

MySQL said: #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 'INSERT INTO temp CALL stored_procedure1();

I tried changing syntax of TABLE temp to TABLE #temp and adding ; at the end of create table statement which did not resolve it.

NaN
  • 1,012
  • 3
  • 13
  • 25
  • Possible duplicate of [MySQL How to INSERT INTO \[temp table\] FROM \[Stored Procedure\]](http://stackoverflow.com/questions/687102/mysql-how-to-insert-into-temp-table-from-stored-procedure) – Isaac Bennetch Aug 23 '16 at 14:34

1 Answers1

0

First, you should change default delimiter which is ; to something like //

Also, i assume you forgot to put CREATE PROCEDURE Something() statement here.

DELIMITER //
CREATE PROCEDURE Something()
BEGIN
CREATE TABLE temp(Name VARCHAR(200), Value1 varchar(100), Value2 varchar(100));
INSERT INTO temp CALL stored_procedure1();
INSERT INTO temp CALL stored_procedure2();
END//
DELIMITER ;
Amir
  • 4,089
  • 4
  • 16
  • 28
  • Thanks for your reply, I tried using delimiters which gives me the following syntax error message MySQL said: #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 '// CREATE PROCEDURE get_data() – NaN Aug 18 '16 at 10:52
  • I tried modifying the code as per your latest reply, now it gives me the following error MySQL said: #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 '// CREATE PROCEDURE get_data() BEGIN CREATE TABLE temp(Name VARCHAR(200), V' at line 3 – NaN Aug 18 '16 at 11:01
  • FYI I am working on PHPmyadmin edit routine window to add or edit the SP – NaN Aug 18 '16 at 11:01