国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

模擬字符串處理函數(shù) stuff 的存儲過程,對 ntext 字段進行stuff .

2024-07-21 02:11:48
字體:
供稿:網(wǎng)友
if exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[p_stuff]') and objectproperty(id, n'isprocedure') = 1)
drop procedure [dbo].[p_stuff]
go

/*--ntext字段處理

模擬字符串處理函數(shù) stuff
完成表中 ntext 字段的 stuff 處理
注意,表中需要有列名為:id 的主鍵(或標識字段),數(shù)據(jù)類型為int
如果沒有這個主鍵字段,或者是其他類型,則對應(yīng)的需要修改存儲過程

--鄒建 2004.07--*/

/*--調(diào)用示例

--測試數(shù)據(jù)
create table tb(id int identity(1,1),content ntext)
insert tb select 'a;sd'
union all select 'a;sdfkjas2qasdfdfsg45yhjhdfg45645a'

--調(diào)用存儲過程,將第8~9的字符替換成'中國'
exec p_stuff 'tb','content',8,2,'中國',''
select * from tb

drop table tb
--*/

create proc p_stuff
@tbname sysname,--要處理的表名
@fdname sysname,--text/ntext字段名
@start int=null,--開始位置,null表示追加數(shù)據(jù)
@length int=null,--替換的長度
@str nvarchar(4000),--要插入的字符串
@where nvarchar(1000)=''--要處理的記錄的條件
as
if @str is null return
declare @s nvarchar(4000)
set @s='
declare @id int,@ptr varbinary(16),@start1 int

declare tb cursor local for
select id,start=datalength(['[email protected]+'])/2
from ['[email protected]+']
'+case isnull(@where,'') when '' then ''
else ' where '[email protected] end+'

open tb
fetch tb into @id,@start1
while @@fetch_status=0
begin
select @ptr=textptr(content)
from ['[email protected]+']
where [email protected]

if @start is null or @start1<@start
updatetext ['[email protected]+'].['[email protected]+'] @ptr null null @str
else
begin
set @[email protected]
updatetext ['[email protected]+'].['[email protected]+'] @ptr @start1 @length @str
end
fetch tb into @id,@start1
end
close tb
deallocate tb
'
exec sp_executesql @s
,n'@start int,@length int,@str nvarchar(4000)'
,@start,@length,@str
go

中國最大的web開發(fā)資源網(wǎng)站及技術(shù)社區(qū),
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 白朗县| 昌乐县| 夏邑县| 梁平县| 通许县| 蓬莱市| 如皋市| 遂宁市| 安图县| 剑河县| 西吉县| 黄骅市| 台北县| 靖西县| 大庆市| 太保市| 佛冈县| 惠安县| 房产| 遂宁市| 定西市| 专栏| 双桥区| 绥棱县| 图木舒克市| 双流县| 玛纳斯县| 松潘县| 池州市| 滨海县| 禹城市| 彭山县| 西峡县| 芦山县| 莲花县| 榕江县| 吴忠市| 平利县| 平利县| 宁强县| 车致|