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

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

如何將圖片存到數(shù)據(jù)庫中?

2024-07-21 02:30:45
字體:
供稿:網(wǎng)友
如果你用的是sql server數(shù)據(jù)庫!你不想用后臺(tái)操作你可以看看這個(gè)
下面是對(duì)text的操作你可以看看
1. 寫操作(WRITETEXT)
這里一般要用到的函數(shù)有TextPtr獲得文本字段的指針,和TextVaild檢驗(yàn)指針的有效性,@@RowCount判斷返回記錄的條數(shù)。
其基本方法是:用Textptr函數(shù)得到指針,判斷其有效性,用Writetext寫數(shù)據(jù)
函數(shù)說明:Textptr(字段名)。Writetext   tablename。Fieldname   @textptr(指針) [With Log]  data(數(shù)據(jù))
例如:
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. 讀操作
常用函數(shù)
PatIndex(‘%exp%’,var|fieldname。。)
Datalength()
@@TextSize 文本大小
SettextSize  N 設(shè)置文本大小
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.?dāng)?shù)據(jù)更新UpdateText
更新數(shù)據(jù)代替了寫操作,其基本語法是:
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表示你向當(dāng)前內(nèi)容追加數(shù)據(jù)。
Deleted_Length:0表示不刪除任何內(nèi)容,Null表示刪除所有內(nèi)容。
例如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
/*減一是因?yàn)橛幸粋€(gè)矯正的偏移量,加4是因?yàn)镈.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的內(nèi)容追加到出版商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


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 哈巴河县| 许昌市| 和龙市| 昭平县| 荣昌县| 裕民县| 潢川县| 成武县| 关岭| 桑日县| 思南县| 云梦县| 碌曲县| 遵化市| 金湖县| 海城市| 介休市| 琼结县| 南昌县| 灯塔市| 若尔盖县| 郯城县| 景德镇市| 资源县| 卢龙县| 溧阳市| 缙云县| 阳西县| 丹巴县| 策勒县| 乌鲁木齐县| 拉孜县| 丰都县| 兰考县| 会理县| 扬州市| 鄯善县| 富阳市| 岳阳市| 瓦房店市| 红安县|