Search and replace part of string in database

前端 未结 6 1914
余生分开走
余生分开走 2020-12-04 21:11

I need to replace all iframe tags, stored as nvarchar in my database. I can find the entries using the following sql-question:

SELECT * FROM databasename..Ve         


        
相关标签:
6条回答
  • 2020-12-04 22:00

    I would consider writing a CLR replace function with RegEx support for this kind of string manipulation.

    0 讨论(0)
  • 2020-12-04 22:02

    I think 2 update calls should do

    update VersionedFields
    set Value = replace(value,'<iframe','<a><iframe')
    
    update VersionedFields
    set Value = replace(value,'> </iframe>','</a>')
    
    0 讨论(0)
  • 2020-12-04 22:05
    update VersionedFields
    set Value = replace(replace(value,'<iframe','<a>iframe'), '> </iframe>','</a>')
    

    and you do it in a single pass.

    0 讨论(0)
  • 2020-12-04 22:05

    Update database and Set fieldName=Replace (fieldName,'FindString','ReplaceString')

    0 讨论(0)
  • 2020-12-04 22:06

    You can do it with an UPDATE statement setting the value with a REPLACE

    UPDATE
        Table
    SET
        Column = Replace(Column, 'find value', 'replacement value')
    WHERE
        xxx
    

    You will want to be extremely careful when doing this! I highly recommend doing a backup first.

    0 讨论(0)
  • 2020-12-04 22:09

    I was just faced with a similar problem. I exported the contents of the db into one sql file and used TextEdit to find and replace everything I needed. Simplicity ftw!

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