How to declare a variable and mysql update in liquibase

前端 未结 2 1051
温柔的废话
温柔的废话 2021-01-20 06:40

I want to write the following sql code in liquibase

set @value1 = \"string1\"; set @value2 = \"string2\";

update users set category = REPLACE(category, @valu

2条回答
  •  深忆病人
    2021-01-20 06:49

    If you want to declare and set variables within a changeset's 'sql' tag you just need to remove the ";".

    By default liquibase uses ";" to execute, and variables are scoped within an execution. So while this will not work:

    DECLARE @value1 varchar(10);
    SET @value1 = "string1";
    

    This will work:

    DECLARE @value1 varchar(10)
    SET @value1 = "string1"
    

    I left off the last ";" on the initialization as I assume you want to do something with the variable

提交回复
热议问题