0

The below code works correctly when I use command line (mysql.exe) to execute, but incorrect when I use SQL Query in phpmyadmin or using ScriptRunner (Java) to execute.

The error: Error Syntax execute DELIMITER $$

How can I solve this problem?

-- Procedures
-- 
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `upload_photo`(
IN owner_id int, IN photo_name text, IN photo_url text, IN thumbnail text
)
begin
declare inserted_id int unsigned default 0;
INSERT INTO photo(`owner_id`, `photo_name`, `photo_url`, `thumbnail`) VALUES(owner_id, photo_name, photo_url, thumbnail);
 set inserted_id = last_insert_id();
 select * from photo where photo_id = inserted_id;
end$$

-- 
DELIMITER ;
Luc
  • 2,800
  • 2
  • 25
  • 46
  • Use a different delimiter, perhaps? –  Aug 07 '13 at 09:30
  • @MikeW: Thanks for reply. But I got the same error. :D – Luc Aug 07 '13 at 09:31
  • Possible duplicate of [this thread](http://stackoverflow.com/questions/9017269/mysql-delimiter-syntax-error) – Rik Aug 07 '13 at 09:39
  • @Rik. Thanks for supporting. But I don't think this post can solve my problem. If you can. Please help me. – Luc Aug 07 '13 at 09:47
  • What version of phpmyadmin are you using? Does it have a delimiter-input-box below the sql-statement? – Rik Aug 07 '13 at 10:10
  • 1
    Not all versions of phpMyAdmin recognise the delimiter command; instead, one can use the Delimiter input box beneath the SQL input box. [See here](http://stackoverflow.com/questions/2454071/how-do-i-write-an-sp-in-phpmyadmin-mysql/2498437#2498437) – Rik Aug 07 '13 at 10:14
  • I'm using Java to execute command (ScriptRunner.Java) – Luc Aug 07 '13 at 10:35
  • 1
    I don't know ScriptRunner personally but i think it also doesn't know the `DELIMITER` keyword. But can't you set the delimiter with `setDelimiter("$$", true)` before the `Runscript` and leave out the `DELIMITER` keywords? – Rik Aug 07 '13 at 11:48

3 Answers3

1

PhpMyAdmin uses mysqli which doesn't support delimiter. See if delimiter is needed at all. I am running a script with multiple rows and my MySQL runs all of them with semicolons as delimiters.

Volt
  • 99
  • 1
  • 7
  • Just checked. Delimiter is not needed for MySQL. Only needed to pass queries. Mysqli->query only sends one query (you would need mysqli->multi_query). So since you can only pass one query, delimiter is not needed because it will always be one query regardless how many semicolons it will have. – Volt Apr 26 '17 at 15:58
1

I found a solution here and it works for me (i'm using ScriptRunner):

just use -- @DELIMITER $$ instead of DELIMITER $$

lousuan
  • 79
  • 1
  • 6
0

I just ran into a similar issue where my DELIMITER statement was breaking when run via Flyway despite working when I ran it through my sql client.

The issue was either indentation or hidden special characters because formatting the code in the IDE fixed the issue.

geg
  • 4,399
  • 4
  • 34
  • 35