jiafan

blog with .net,c# and php

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
如果接触过mysql的话一定对mysql的text和blob不会陌生,在mysql中是直接操作text和blob的。但是在oracle中,它把lob做为一种特殊的字段,不能直接进行操作--比如不能直接插入到lob字段中,也不能用like查询等等。     
  不能直接用INSERT语句向LOB字段中插入值。一般情况下,有如下的几步:    
  1   先分析一个INSERT语句,返回一个LOB的描述符    
  2   用OCI函数生成一个本地的LOB对象    
  3   将LOB对象绑定到LOB描述符上    
  4   执行INSERT语句    
  5   给LOB对象赋值    
  6   释放LOB对象和SQL语句句柄     
 /*  
  //(tabel_name:article)DDL;   //just   for   test;    
  //create   table   article(id   number(11),content   clob);    
  */  
   
  //----------This   is   insert   test----------------------------------    
  $conn   =   @OCILogon("YourUsername","YourPassword","YourDatabase");  
   
  $stmt   =   @OCIParse($conn,"insert   into   article   values(1,EMPTY_CLOB())   RETURNING   content   INTO:CONTENT");    
  $clob   =   @OCINewDescriptor($conn,OCI_D_LOB);   
    OCIBindByName($stmt,':CONTENT',&$clob,-1,OCI_B_CLOB);
if(!OCIExecute($stmt, OCI_DEFAULT)) {print_r(OCIError($stmt));}
if($clob->save($CONT))
{
OCICommit($conn);
}
else
{
print_r(OCIError($stmt));
    
  //---------------Insert   end-----------------------------------------  
   
   
  //---------------Select   start---------------------------------------  
  $sql   =   "select   content   from   article   order   by   id   desc";  
  $stmt   =   @OCIParse($conn,$sql);  
  @OCIExecute($stmt,OCI_DEFAULT);  
  @OCIFetchInto($stmt,&$rows,OCI_RETURN_LOBS);  
  echo   "<br>Content   is:\"".$rows[0]."\"";  
   
  //---------------Select   end-----------------------------------------

注意:测试时一定注意Oracle的保留关键字,经常使用OCIError来差错。
posted on 2008-06-23 16:54  jiafan  阅读(2042)  评论(0编辑  收藏  举报