午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    SQL 正則表達式 模糊替換字段內容
    來源:易賢網(wǎng) 閱讀:1029 次 日期:2014-09-15 10:22:25
    溫馨提示:易賢網(wǎng)小編為您整理了“SQL 正則表達式 模糊替換字段內容”,方便廣大網(wǎng)友查閱!

    oracle里有現(xiàn)成的正則替換函數(shù)REGEXP_REPLACE,可SQL SERVER里沒有 只能自己創(chuàng)建一個

    --SQL正則替換函數(shù)

    CREATE function dbo.regexReplace

    (

    @source ntext, --原字符串

    @regexp varchar(1000), --正則表達式

    @replace varchar(1000), --替換值

    @globalReplace bit = 1, --是否是全局替換

    @ignoreCase bit = 0 --是否忽略大小寫

    )

    returnS varchar(1000) AS

    begin

    declare @hr integer

    declare @objRegExp integer

    declare @result varchar(5000)

    exec @hr = sp_OACreate 'VBScript.RegExp', @objRegExp OUTPUT

    IF @hr <> 0 begin

    exec @hr = sp_OADestroy @objRegExp

    return null

    end

    exec @hr = sp_OASetProperty @objRegExp, 'Pattern', @regexp

    IF @hr <> 0 begin

    exec @hr = sp_OADestroy @objRegExp

    return null

    end

    exec @hr = sp_OASetProperty @objRegExp, 'Global', @globalReplace

    IF @hr <> 0 begin

    exec @hr = sp_OADestroy @objRegExp

    return null

    end

    exec @hr = sp_OASetProperty @objRegExp, 'IgnoreCase', @ignoreCase

    IF @hr <> 0 begin

    exec @hr = sp_OADestroy @objRegExp

    return null

    end

    exec @hr = sp_OAMethod @objRegExp, 'Replace', @result OUTPUT, @source, @replace

    IF @hr <> 0 begin

    exec @hr = sp_OADestroy @objRegExp

    return null

    end

    exec @hr = sp_OADestroy @objRegExp

    IF @hr <> 0 begin

    return null

    end

    return @result

    end

    --把字段NewsContent中包含 width='***' height='***'/> 的內容替換成 />

    查詢

    Select NewsID,dbo.regexReplace(NewsContent,'width=([^>])*>','/>',1,0) AS NewsConten_temp From Encyclopedia_temp

    替換

    update Encyclopedia_temp set NewsContent = dbo.regexReplace(NewsContent,'width=([^>])*>','/>',1,0) where NewsContent LIKE '% width=%'

    更多信息請查看IT技術專欄

    更多信息請查看數(shù)據(jù)庫
    易賢網(wǎng)手機網(wǎng)站地址:SQL 正則表達式 模糊替換字段內容

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)