Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase: SQL syntax error in a MySQL stored procedure

I tried to run the MySQL stored procedure SQL script by Liquibase, but never worked.

The content of db.storedprocedure.xml:

<changeSet author="zzz" id="1" runOnChange="true" runInTransaction="true">
    <sqlFile path="changelogs/change_03.sql"
         relativeToChangelogFile="true"
         endDelimiter="$$"
         stripComments="false"
         splitStatements="false"/>
</changeSet>

The content of my SQL file change_03.sql:

$$

CREATE PROCEDURE `liqui01`.`User_Search`(
    INOUT id INT,
    OUT name VARCHAR(50)
)
BEGIN

    SET @sql = CONCAT("SELECT id, name FROM user WHERE da.MarketId = ", id );

    PREPARE stmt from @sql;
    EXECUTE stmt;

END$$

It shows the error like:

Unexpected error running Liquibase: 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 '$$ ...

I've tried to change the "$$" to other delimiters, or put the SQL inside <sql> tags of the XML file, all didn't work.

Any advise would be appreciated!

Update 1

@Shadow has given the correct answer (unfortunately I cannot mark it as the answer because it's in the comments), removing the delimeter lines from the sql scripts will make it work, thanks for him!

Now the question is: How to use "endDelimiter" parameter?


1 Answers

Please refer the official Liquibase documentation link : here which mentions about escaping the delimiter character $$ like \$\$.

When setting an end-delimiter, note that certain DBMS and operating systems require delimiter values to be escaped. For example, a $$ end-delimiter with mysql requires escaping as: end-delimiter="$$".

like image 113
Rakhi Agrawal Avatar answered Mar 22 '26 12:03

Rakhi Agrawal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!