How to use sql procedure or while/for loop in liquibase 4.0.0?

1.4k views Asked by At

I want to use for/while loop in sql file. So defined the proc sql. btw there is an error.

<changeSet id="trade_proc" author="alex">
        <sqlFile endDelimiter="//" path="trade.h2.proc.sql" stripComments="true" />
    </changeSet>

----------------------- sql file ---------

drop procedure if exists proc;

create procedure proc()

begin
declare v_max int unsigned default 3;
declare v_counter int unsigned default 0;
while v_counter < v_max do  
...

end while;
end //

--------------- error ------------ Unexpected error running Liquibase: Migration failed for change set changelog.xml::trade_history_20200728_proc::alex: Reason: liquibase.exception.DatabaseException: 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 'create procedure proc()

begin declare v_max' at line 3 [Failed SQL: (1064) drop procedure if exists proc;

create procedure proc()

======== What's the reason? or please help me how to use while/for loop in liquibase mysql. Thank you.

0

There are 0 answers