模拟字符串处理函数 stuff 处理 Ntext 字段
2008-05-01 02:57
639 查看
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字段处理
模拟字符串处理函数 stuff 完成表中 Ntext 字段的 stuff 处理 注意,表中需要有列名为:id 的主键(或标识字段),数据类型为int 如果没有这个主键字段,或者是其他类型,则对应的需要修改存储过程
--邹建 2004.07--*/
/*--调用示例
--测试数据 create table tb(id int identity(1,1),content Ntext) insert tb select 'a;sd' union all select 'a;sdfkjas2qasdfdfsg45yhjhdfg45645a' --调用存储过程,将第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表示追加数据@length int=null, --替换的长度@str nvarchar(4000),--要插入的字符串@where nvarchar(1000)=''--要处理的记录的条件asif @str is null returndeclare @s nvarchar(4000)set @s='declare @id int,@ptr varbinary(16),@start1 int
declare tb cursor local for select id,start=datalength(['+@fdname+'])/2from ['+@tbname+']'+case isnull(@where,'') when '' then '' else ' where '+@where end+'
open tb fetch tb into @id,@start1while @@fetch_status=0begin select @ptr=textptr(content) from ['+@tbname+'] where id=@id
if @start is null or @start1<@start updatetext ['+@tbname+'].['+@fdname+'] @ptr null null @str else begin set @start1=@start-1 updatetext ['+@tbname+'].['+@fdname+'] @ptr @start1 @length @str end fetch tb into @id,@start1endclose tbdeallocate tb'exec sp_executesql @s ,N'@start int,@length int,@str nvarchar(4000)' ,@start,@length,@strgo
/*--Ntext字段处理
模拟字符串处理函数 stuff 完成表中 Ntext 字段的 stuff 处理 注意,表中需要有列名为:id 的主键(或标识字段),数据类型为int 如果没有这个主键字段,或者是其他类型,则对应的需要修改存储过程
--邹建 2004.07--*/
/*--调用示例
--测试数据 create table tb(id int identity(1,1),content Ntext) insert tb select 'a;sd' union all select 'a;sdfkjas2qasdfdfsg45yhjhdfg45645a' --调用存储过程,将第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表示追加数据@length int=null, --替换的长度@str nvarchar(4000),--要插入的字符串@where nvarchar(1000)=''--要处理的记录的条件asif @str is null returndeclare @s nvarchar(4000)set @s='declare @id int,@ptr varbinary(16),@start1 int
declare tb cursor local for select id,start=datalength(['+@fdname+'])/2from ['+@tbname+']'+case isnull(@where,'') when '' then '' else ' where '+@where end+'
open tb fetch tb into @id,@start1while @@fetch_status=0begin select @ptr=textptr(content) from ['+@tbname+'] where id=@id
if @start is null or @start1<@start updatetext ['+@tbname+'].['+@fdname+'] @ptr null null @str else begin set @start1=@start-1 updatetext ['+@tbname+'].['+@fdname+'] @ptr @start1 @length @str end fetch tb into @id,@start1endclose tbdeallocate tb'exec sp_executesql @s ,N'@start int,@length int,@str nvarchar(4000)' ,@start,@length,@strgo
相关文章推荐
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 的存储过程,对 ntext 字段进行stuff .
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 的存储过程,对 ntext 字段进行stuff
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数stuff处理Ntext字段
- 字符串处理函数的模拟实现(strlen、strstr、strcat、strcmp、strcpy、memmove、memcpy)
- 处理text,ntext,image字段的函数
- 模拟库中的字符串处理函数
- sql2000中ntext字段字符串分割函数
- hdu 2412 (disney) 模拟、字符串处理
- Oracle 存储过程总结 二、字符串处理相关函数
- Python内置的字符串处理函数整理