如果你用的是sql server数据库!你不想用后台操作你可以看看这个
下面是对text的操作你可以看看
1. 写操作(WRITETEXT)
这里一般要用到的函数有TextPtr获得文本字段的指针,和TextVaild检验指针的有效性,@@RowCount判断返回记录的条数。
其基本方法是:用Textptr函数得到指针,判断其有效性,用Writetext写数据
函数说明:Textptr(字段名)。Writetext tablename。Fieldname @textptr(指针) [With Log] data(数据)
例如:
Begin Tran
Declare @Mytextptr VarBinary(16)
Select @mytextptr=textptr(pr_info)
From Pub_Info (updlock)
Where pud_id=’9999’
IF @Mytextptr Is Not Null
Writetext pub_info.pr_info @mytextptr with log ‘data’
Commit Tran
2. 读操作
常用函数
PatIndex(‘%exp%’,var|fieldname。。)
Datalength()
@@TextSize 文本大小
SettextSize N 设置文本大小
ReadText {TableName。FieldName} {@textptr} Offet Size [HoldLock]
例如:
begin tran
Declare @mytextptr Varbinary(16),@Totalsize int,@Readsize int,@lastread int
Set textsize 100
Select @mytextptr=textptr(pr_info), @totalsize=datalength(pr_info)
@lastread=0,
@readsize= case when (textsize
1<datalength(pr_info) @mytextptr="" @readsize="" and="" datalength(pr_info)="" eles="" end="" from="" if="" is="" not="" null="" pub_id="’1622’" pub_info="" textsize="" then="" where="">0
2While (@lastread<@totalsize)
3ReadText pub_info.pr_info @mytextptr @lastread @readsize holdlock
4If (@@error<>0)
5Break
6Select @lastread=@lastread+@readsize
7If ((@readsize+@lastread)>@totalsize)
8Select @readsize=@totalsize-@lastread
9End
10Commit Tran
113.数据更新UpdateText
12更新数据代替了写操作,其基本语法是:
13UpdateText Table_Name.Col_Name Text_Ptr Offest(偏移量) Deleted_Length
14[With Log] [Inserted_Data|Table_Name.Scr_Column_name Str_Text_Ptr]
15说明:
16Offest:0说明从开头开始,Null表示你向当前内容追加数据。
17Deleted_Length:0表示不删除任何内容,Null表示删除所有内容。
18例如1(完全代替):
19Declare @mytextptr varbinary(16)
20Begin tran
21Select @mytextptr=textptr(pr_infro) from pub_info(uplock) where pub_id=’9999’
22If @mytextptr is not null
23Updatetext pub_info.pr_infro @mytextptr 0 null with log “you are right”
24Commit
25例如2:
26declare @mytextptr varbinary(16) ,@offest int
27Begin tran
28Select @mytextptr=textptr(pr_infro),@offest=patindex(‘%D.C%’,pr_infro)-1+4
29/*减一是因为有一个矫正的偏移量,加4是因为D.C.是4*/
30from pub_info(unlock) where pub_id=’0877’
31If @mytextptr is not null and @offest>=0
32Updatetext pub_info.pr_infro @mytextptr @offest null with log
33Commit tran
34例如3:
35文本追加的问题
36将出版商pub_id=9952的内容追加到出版商Pub_id=0877d的文本中。
37Delcare @source_textptr varbinary(16),@target_textptr varbinary(16)
38Begin tran
39Select @source_textptr=textptr(pr_infro) from pub_info(uplock) where pub_id=’0877’
40Select @target_textptr=textptr(pr_infro) from pub_info(uplock) where pub_id=’9952’
41If @source_textptr Is not null and @target I s not null
42Updatetext pub_info.pr_infro @target_textptr null null
43with log pub_info.pr_infro @source_textptr</datalength(pr_info)>