error when doing procedure with cursor

0

I try to do this

CREATE PROCEDURE temporal( IN temp INT)
BEGIN

 DECLARE maxima INT
 SELECT MAX(ventas) FROM vendedor INTO maxima;
 CREATE TABLE ven_temp AS SELECT id_vendedor FROM vendedor;
 WHERE ventas=maxima;
 COMMIT;
 END;

mark me:

error #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 max(ventas) FROM vendedor INTO maxima' at line 5 

quito "." and commas and remains the same, I do not know what is due

I think it may be the version but I do not know how to make the version that I use this

PHP version: 5.5.38 phpmyadmin About this version: 4.5.1

    
asked by wdwdwd 21.04.2017 в 09:19
source

2 answers

0

The correct syntax for select into is

select columna1, columna2,... columnaN into var1, var2,...varN from tablaX

Applied to your code:

CREATE PROCEDURE temporal( IN temp INT)
BEGIN

 DECLARE maxima INT
 SELECT MAX(ventas) INTO maxima FROM vendedor;
 CREATE TABLE ven_temp AS SELECT id_vendedor FROM vendedor;
 WHERE ventas=maxima;
 COMMIT;
 END;
    
answered by 21.04.2017 в 10:12
0

Try with:

DECLARE maxima INT;
SET maxima = (SELECT MAX(ventas) FROM vendedor);

You can also verify that your query is correct.

Greetings and comment any

    
answered by 21.04.2017 в 09:30