使用子字符串根据条件更新列值
Updating column value based on condition with substring
我需要将包含 autor
子字符串的列的所有值更改为 author
。
示例:我当前的行是 role-autor
,这需要变成 role-author
在 liquibase 中可以吗?
你只想replace()
吗?
update t
set col = replace(col, 'autor', 'author')
where col like '%autor%';
像这样:
<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>
请研究一下 Whosebug 博客,其中有一些示例可以帮助您...
您需要将其放入变更集标签中:
<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.com/concepts/basic/changeset.html
我需要将包含 autor
子字符串的列的所有值更改为 author
。
示例:我当前的行是 role-autor
,这需要变成 role-author
在 liquibase 中可以吗?
你只想replace()
吗?
update t
set col = replace(col, 'autor', 'author')
where col like '%autor%';
像这样:
<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>
请研究一下 Whosebug 博客,其中有一些示例可以帮助您...
您需要将其放入变更集标签中:
<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.com/concepts/basic/changeset.html