文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

您的位置:首页技术开发数据库技巧 → 如何将图片存到数据库中?

如何将图片存到数据库中?

时间:2004/11/15 23:33:00来源:本站整理作者:蓝点我要评论(0)

如果你用的是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
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




相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 mssql企业管理器不能打 Oracle PRKC-1002错误原因和解决方案SQL SERVER数据库日志清空图文教程win2003计算机改名后sql server 2005 本地复DB2错误信息码大全

人气排行 彻底解决mysql中文乱码的办法mysql数据库root密码忘记的修改方法SQL SERVER数据库日志清空图文教程.bak备份文件如何恢复Oracle PRKC-1002错误原因和解决方案Oracle错误代码大全如何将txt的文本数据导入SQL server 2005呢DB2错误信息码大全