MSDN里写得很详细的,最好自己去仔细看一下
解决方案 »
- 一个简单问题求教
- 锋利的SQL书中运行的代码有错误
- sql 行转列的函数该怎么写
- 在线等一道面试题答案
- 求一个有关查询的sql语句
- 急求:如何解决 SQL Server 安装程序中的 COM+ 系统配置检查失败问题?
- 比较出色又相对不太复杂的 安装文件制作工具有没有?比如 FLashGet安装文件用什么做的?谢谢!
- 关于sql连接池的问题
- 请教一个Sybase和MS sql 的区别问题
- vista下 安裝sql 2000 出現怪異的問題.
- 急!新手请教:有个价格信息表由3个字段组成名称(name),金额(price),日期(IssueTime),想得到一个由名称,year1总金额,year2...总金额组成的各年度总金额统计表,不知SQL语句该怎么写?
- 请问各位大侠,我怎样才能得到的Oracle存储过程的返回值,在程序中!
这里一般要用到的函数有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<datalength(pr_info) then textsize
eles datalength(pr_info)
end
From Pub_info
Where Pub_id=’1622’
IF @mytextptr Is not Null and @readsize>0
While (@lastread<@totalsize)
ReadText pub_info.pr_info @mytextptr @lastread @readsize holdlock
If (@@error<>0)
Break
Select @lastread=@lastread+@readsize
If ((@readsize+@lastread)>@totalsize)
Select @readsize=@totalsize-@lastread
End
Commit Tran
3.数据更新UpdateText
更新数据代替了写操作,其基本语法是:
UpdateText Table_Name.Col_Name Text_Ptr Offest(偏移量) Deleted_Length
[With Log] [Inserted_Data|Table_Name.Scr_Column_name Str_Text_Ptr]
说明:
Offest:0说明从开头开始,Null表示你向当前内容追加数据。
Deleted_Length:0表示不删除任何内容,Null表示删除所有内容。
例如1(完全代替):
Declare @mytextptr varbinary(16)
Begin tran
Select @mytextptr=textptr(pr_infro) from pub_info(uplock) where pub_id=’9999’
If @mytextptr is not null
Updatetext pub_info.pr_infro @mytextptr 0 null with log “you are right”
Commit
例如2:
declare @mytextptr varbinary(16) ,@offest int
Begin tran
Select @mytextptr=textptr(pr_infro),@offest=patindex(‘%D.C%’,pr_infro)-1+4
/*减一是因为有一个矫正的偏移量,加4是因为D.C.是4*/
from pub_info(unlock) where pub_id=’0877’
If @mytextptr is not null and @offest>=0
Updatetext pub_info.pr_infro @mytextptr @offest null with log
Commit tran
例如3:
文本追加的问题
将出版商pub_id=9952的内容追加到出版商Pub_id=0877d的文本中。
Delcare @source_textptr varbinary(16),@target_textptr varbinary(16)
Begin tran
Select @source_textptr=textptr(pr_infro) from pub_info(uplock) where pub_id=’0877’
Select @target_textptr=textptr(pr_infro) from pub_info(uplock) where pub_id=’9952’
If @source_textptr Is not null and @target I s not null
Updatetext pub_info.pr_infro @target_textptr null null
with log pub_info.pr_infro @source_textptr
这是sql server对图形的操作
一般前台语言有这种功能你可以看看
在VB程序中作如下处理
Dim b() As Byte
Dim i As Long
i = FreeFile
Open "c:\tt.jpg" For Binary As #i
ReDim b(LOF(i))
Get #i, , b
Close #i
rs.addnew
rs.fields("tt").appendchunk b
rs.update
With rs
LenF = .Fields("tt").ActualSize
ReDim b(LenF)
b= .Fields("FData").GetChunk(LenF)
End With
strBuffer = "C:\test.jpg"
If Dir(strBuffer) <> "" Then
Kill strBuffer
End If
Dim fileNo As Integer
fileNo = FreeFile()
Open strBuffer For Binary As #fileNo
Put #fileNo, , b
Close #fileNo