0

我知道如何更新记录并替换另一个字符串中的子字符串:

update(conn,'tableName',{'columnName'},{'value'},'where columName=xx') %update record in database

modifiedStr = strrep(origStr, oldSubstr, newSubstr) %replaces substring with new string in another string.

现在我想混合这两者并更改数据库中记录的子字符串。我们怎么能做到这一点?我想要一个查询来做到这一点。我们可以将两者混合吗?

4

1 回答 1

0

如果只处理一列,则不需要 {} 括号。

如果您有一个列名并将其保存在变量 columnName 中,您可以尝试类似的方法:

columnName = 'product_id';
whereClause = ['where ',columName,'=',origStr];
modifiedStr = strrep(origStr, oldSubstr, newSubstr);
update(conn,'tableName',columnName,modifiedStr,whereClause);

当然,您不需要使用变量,您可以在更新函数中替换所需的字符串,但我这样做是为了澄清。

于 2013-02-26T08:38:56.630 回答