2016-08-03 61 views
0

我想我知道這個解決方案,但我想獲得第二個意見。OLEDB將Oracle LONG數據類型截斷爲100個字符

我有一個名爲Get-Data的函數,它從Oracle數據庫中檢索並返回一個DataTable。現在,由於Powershell超級有用,當從Oracle返回一條記錄時,該函數將返回DataRow而不是DataTable。

發生這種情況並且其中一列是LONG DataType時,該字段被截斷爲100個字符。

明顯的解決辦法是返回$ dt並修改我的代碼來處理該問題。但是,正如我所說,我想要第二個意見。

獲取-數據:

function Get-Data 
    { 
     [Cmdletbinding()] 
     Param 
     (
      [Parameter(Position=0,Mandatory=$True)]$Conn, 
      [Parameter(Position=1,Mandatory=$True)]$sql 
     ) 
      #Open the connection to the DB if closed 
        if($Conn.state -eq 'Closed') 
      { 
       $Conn.open() 
      } 

      #Create objects for querying the DB 
      $readcmd = New-Object system.Data.OleDb.OleDbCommand($sql,$Conn) 
      $readcmd.CommandTimeout = '300' 
      $da = New-Object system.Data.OleDb.OleDbDataAdapter($readcmd) 
      $dt = New-Object system.Data.datatable 

      #Query the DB and fill the DataTabe with records 

      [void]$da.fill($dt) 

      return $dt 
    } 
+0

我試圖返回,dt的變化,無濟於事。只要返回一條記錄,問題就會一直存在。 –

回答

0

好了,所以我找到了問題的根源。

當使用此SQL語句從表中有LONG數據類型中進行選擇:當使用下面的查詢,而不是對同一

Select * from [table] 

OLEDB從ORACLE

返回LONG場的全部內容表:

Select distinct * from [table] 

OLEDB只返回第一100個的LONG字段的字符

+0

在Oracle SQL Developer中運行相同的查詢時,我收到了LONG字段的全部內容。 –

相關問題