• 0

[MySql SQL] What is the DELIMITER about?!


Question

Im confident with SQL and normally use SQL Server. But im messing about with MySql and having a nightmare with some simple stored procedures.

One minute my code is fine, the next it has syntax errors - AND I HAVENT CHANGED THE CODE!

The error points at the first line reading 'DELIMITER $$' - what is this DELIMITER for? I tried taking it out before and it didnt work. Can anyone shine a light here?

3 answers to this question

Recommended Posts

  • 0

MySQL uses a special character (the "delimiter") to mark the end of a command. When loading the stored procedure into memory, MySQL parses that file and treats the input characters literally. Therefore, when it encounters the delimiter while loading the file, it begins executing the stored procedure as if you had just typed it into the console. And since the file hasn't finished loading yet, you get errors. In order to prevent this, it is necessary to change the delimiter to something else temporarily in order to suppress immediate execution. Then, after the stored procedure has been loaded into memory, change the delimiter back into what it was before.

  • 0
  $phinX said:

So, i load the script into Query Browser app. Change the $$ delimiter to //, run it, change it back to $$ and it works, yeah?

Depends on what delimiter you used inside your script file. If it is //, then yes. If it is $$, then:

Change the $$ delimiter to //,

load the script into Query Browser app,

change it back to $$,

run it

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.