熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

.net中二進制大對象的操作

2022-06-13   來源: Oracle 

  public static void WriteLob(string table_namestring table_idint idint columnstring content)
     {
      OracleConnection myCn = new OracleConnection(strConn);   
      OracleCommand myCmd = new OracleCommand();
      try
      {
       myCnOpen();    
      }
      catch(SystemDataOracleClientOracleException e)
      {
       throw new Exception(eMessage);
      }   
      OracleTransaction myTrans = myCnBeginTransaction();
      try
      {           
       myCmdConnection = myCn;    
       myCmdTransaction = myTrans;
       myCmdCommandText = SELECT * FROM + table_name + where + table_id + = + id + FOR UPDATE;
       OracleDataReader reader = myCmdExecuteReader();
       using(reader)
       {
        readerRead();
        OracleLob CLOB = readerGetOracleLob(column);//column為lob類型所在列
        Encoding UTF = EncodingUTF;        //使用UTF進行編碼
        byte[] buffer = UTFGetBytes(content);
        if(bufferLength % ==)
         CLOBWrite(buffer bufferLength);  //這裡的參數必須為偶數
        else
         CLOBWrite(buffer (bufferLength ));
        //CLOBPosition = ;
        myTransCommit();
       }
      }
      catch(SystemDataOracleClientOracleException e)
      {   
       myTransRollback();
       throw new Exception(eMessage);
      }
      finally
      {
       myCmdDispose();
       myCnClose();
      }
     }
     public static string ReadLob(string table_namestring table_idint idint column)
     {
      OracleConnection myCn = new OracleConnection(strConn);   
      OracleCommand myCmd = new OracleCommand();
      try
      {
       myCnOpen();    
      }
      catch(SystemDataOracleClientOracleException e)
      {
       throw new Exception(eMessage);
      }   
      OracleTransaction myTrans = myCnBeginTransaction();
      try
      {           
       myCmdConnection = myCn;    
       myCmdTransaction = myTrans;
       myCmdCommandText = SELECT * FROM + table_name + where + table_id + = + id + FOR UPDATE;
       OracleDataReader reader = myCmdExecuteReader();
       using(reader)
       {
        readerRead();
        OracleLob CLOB = readerGetOracleLob(column);
        int[] content = new int[(int)CLOBLength];
        byte[] buffer = new byte[(int)CLOBLength];
         
        for(int i = ;i<(int)CLOBLength;i++)
        {
         content = CLOBReadByte();
         buffer = (byte)content;
        }
   
        Encoding utf = EncodingUTF;
        
        string final = utfGetString(buffer);
        myTransCommit();
        return final;
       }
      }
      catch(SystemDataOracleClientOracleException e)
      {   
       myTransRollback();
       throw new Exception(eMessage);
      }
      finally
      {
       myCmdDispose();
       myCnClose();
      }
     }
From:http://tw.wingwit.com/Article/program/Oracle/201311/17736.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.