MySQL - Error con SQL #1064 - You have an error in your SQL syntax;

 
Vista:

Error con SQL #1064 - You have an error in your SQL syntax;

Publicado por ocb (1 intervención) el 04/05/2018 18:28:26
Hola tengo este problema con el SQL y la verdad yo no se mucho de sql , supongo que sera facil solucionarlo si entiendes de SQL , pero no tengo el conocimiento.


1
2
3
4
5
6
7
8
9
10
Error
SQL query:
 
CREATE DEFINER =  `root`@`localhost` PROCEDURE oxide.claim_donation(
 
IN email_address VARCHAR( 255 )
) BEGIN SET email_address = REPLACE( email_address,  '@@',  '@' ) ;
 
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4



Yo primero creo la base de datos y todo eso con este codigo (supongo que no es necesario que ponga esto pero bueno lo pongo por las dudas) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
CREATE TABLE IF NOT EXISTS oxide.ibn_table (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `itransaction_id` VARCHAR(60) NOT NULL,
    `ipayerid` VARCHAR(60) NOT NULL,
    `iname` VARCHAR(60) NOT NULL,
    `iemail` VARCHAR(60) NOT NULL,
    `itransaction_date` DATETIME NOT NULL,
    `ipaymentstatus` VARCHAR(60) NOT NULL,
    `ieverything_else` TEXT NOT NULL,
    `item_name` VARCHAR(255) DEFAULT NULL,
    `claimed` INT(11) NOT NULL DEFAULT '0',
    `claim_date` DATETIME DEFAULT NULL,
    PRIMARY KEY (`id`)
)  ENGINE=MYISAM AUTO_INCREMENT=9 DEFAULT CHARSET=LATIN1;


El problema es cuando pongo este otro codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
CREATE DEFINER=`root`@`localhost` PROCEDURE oxide.claim_donation(IN email_address VARCHAR(255))
BEGIN
 
set email_address = REPLACE(email_address,'@@','@');
 
set @ID = (
select    IBN.id
from    oxide.ibn_table as IBN
where    IBN.iemail = email_address
        and IBN.claimed = 0
        and IBN.claim_date IS NULL
        and IBN.ipaymentstatus = "Completed"
ORDER BY IBN.itransaction_date DESC
LIMIT 1);
 
UPDATE oxide.ibn_table
SET    claimed = 1, claim_date = NOW()
WHERE id = @ID;
 
select    IBN.item_name
from    oxide.ibn_table as IBN
where    IBN.id = @ID;
 
END


Haber si alguien sabe como solucionarlo , gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 953
Oro
Ha mantenido su posición en MySQL (en relación al último mes)
Gráfica de MySQL

Error con SQL #1064 - You have an error in your SQL syntax;

Publicado por leonardo_josue (414 intervenciones) el 04/05/2018 19:25:42
Hola ocd:

No veo ningún error en el código, pero no defines el cambio de DELIMITADOR DE LINEA antes del procedimiento. Recuerda que si no haces esto, entonces el motor trata de ejecutar el código que lleves cada que encuentres un punto y coma (;).

Prueba así:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE oxide.claim_donation(IN email_address VARCHAR(255))
BEGIN
SET email_address = REPLACE(email_address,'@@','@');
SET @ID = (
SELECT    IBN.id
FROM    oxide.ibn_table AS IBN
WHERE    IBN.iemail = email_address
        AND IBN.claimed = 0
        AND IBN.claim_date IS NULL
        AND IBN.ipaymentstatus = "Completed"
ORDER BY IBN.itransaction_date DESC
LIMIT 1);
 
UPDATE oxide.ibn_table
SET    claimed = 1, claim_date = NOW()
WHERE id = @ID;
 
SELECT    IBN.item_name
FROM    oxide.ibn_table AS IBN
WHERE    IBN.id = @ID;
END$$
DELIMITER ;

Saludos
Leo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar