Sqlite: multiple update (find and replace) case insensitive

后端 未结 2 1861
星月不相逢
星月不相逢 2021-01-21 15:10

I use DB Browser for SQLite to visualize and update an sqlite file.

I am able to do run a case sensitive query to update some text like this:

UPDATE ite         


        
相关标签:
2条回答
  • 2021-01-21 15:23

    Nosyara answer works great but it only removes 1 instance at a time.

    I also tried this from here:

    UPDATE itemNotes  
    SET 
      note = SUBSTR(note, 0, INSTR(LOWER(note), 'sometext')) || 'abc' || SUBSTR(note, INSTR(LOWER(note), 'sometext')+sometext_len)
    WHERE 
      note LIKE "%sometext%";
    

    But when I have many occurence of sometext in a field note, then only the first on is removed. Based on a comment on this question, I ended up using python to replace the sqlite, see here

    0 讨论(0)
  • 2021-01-21 15:33

    You need to search substring in LOWER(note), but replace it in original. I don't know where you getting sometext from, assume that you can check it's length. In following example I'll use constant.

    UPDATE itemNotes  
    SET 
      note = SUBSTR(note, 0, INSTR(LOWER(note), 'sometext')) || 'abc' || SUBSTR(note, INSTR(LOWER(note), 'sometext')+sometext_len)
    WHERE 
      INSTR(LOWER(note), 'sometext') >= 0;
    

    !Note: It will work only for one replace at a time.

    0 讨论(0)
提交回复
热议问题