使用子串根据条件更新列值。

问题描述 投票:0回答:2

我需要更改包含以下内容的列的所有值 autor 子串到 author.

例如:我的当前行是 我的当前行是 role-autor 而这需要成为 role-author

在liquibase中可以吗?

sql spring-boot liquibase
2个回答
1
投票

类似这样。

<update tableName="your_table_name">
    <column name="role-autor" type="varchar(64)" valueComputed="REPLACE(role-autor, 'autor', 'author')" />
    <where>role-autor LIKE '%autor%'</where>
</update>

请研究一下StackOverflow博客,那里有一些例子可以帮助你。

你需要把它放在变化集标签中。

<changeSet author="wiki" id="1.0.0-1">
    <update tableName="your_table_name">
        <column name="role-autor" type="varchar(64)" valueComputed="REPLACE(role-autor, 'autor', 'author')" />
        <where>role-autor LIKE '%autor%'</where>
    </update>
</changeset>

关于变化集标签的更多细节,请阅读。https:/docs.liquibase.comconceptsbasicchangeset.html。


1
投票

你只是想 replace()?

update t
    set col = replace(col, 'autor', 'author')
    where col like '%autor%';
© www.soinside.com 2019 - 2024. All rights reserved.