【问题标题】:sqlite query helpsqlite 查询帮助
【发布时间】:2011-03-16 12:08:24
【问题描述】:

我希望在 sqlite 中替换部分字符串。子字符串

我有一个表,其中有一列名为 name。

名字以马特开头的地方,我想用约翰替换它。

例如: “马特史密斯”转到“约翰史密斯”

【问题讨论】:

    标签: sqlite


    【解决方案1】:

    替换实际上会给你这个

    REPLACE("Matt Smith", "Matt", "John")
    

    【讨论】:

    • 是的,你是对的。但我希望对数据库中的所有字段进行替换。所以 REPLACE(ALL, "MATT", "JOHN")
    • 我认为您将不得不编写一个包含所有字段的更新,但您仍然可以这样使用:SET name = REPLACE(name, 'Matt', 'John')
    【解决方案2】:

    你可以试试这个:

    final String[] whereArgs = { "Matt%" };
    final ContentValues args = new ContentValues();
    args.put(NAME_COLUMN, "John");
    int columnsUpdated = this.sqlitedatabase.update(YOUR_TABLE,args,"where name like ?", whereArgs);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-17
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多