2014-09-30 67 views
0

早上好,stackoverflow。我有一個PowerShell腳本,它正在對Oracle數據庫執行SQL查詢,然後獲取結果並將它們傳遞給本地shell命令。它的工作,大多數。發生了什麼是一些結果正在被丟棄,我可以看到的唯一重要意義是它們有幾個具有空值的列(但只有8列中有2列被返回)。當在sQL開發人員中執行查詢時,我會得到所有預期的結果。這個問題適用於$ eventcheck開關,$ statuscheck工作正常。 PowerShell腳本如下:PowerShell腳本數據庫查詢未通過所有結果

param(
    [parameter(mandatory=$True)]$username, 
    [parameter(mandatory=$True)]$password, 
    $paramreport, 
    $paramsite, 
    [switch]$eventcheck, 
    [switch]$statuscheck 
) 

$qry1 = Get-Content .\vantageplus_processing.sql 

$qry2 = @" 
    select max(TO_CHAR(VP_ACTUAL_RPT_DETAILS.ETLLOADER_OUT,'YYYYMMDDHH24MISS')) Completed 

    from MONITOR.VP_ACTUAL_RPT_DETAILS 

    where VP_ACTUAL_RPT_DETAILS.REPORTNUMBER = '$($paramreport)' and VP_ACTUAL_RPT_DETAILS.SITE_NAME = '$($paramsite)' 

    order by completed desc 
"@ 

$connString = @" 
    Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST="HOST")(PORT="1521")) 
    (CONNECT_DATA=(SERVICE_NAME="SERVICE")));User ID="$username";Password="$password" 
"@ 

function Get-OLEDBData ($connectstring, $sql) { 
    $OLEDBConn = New-Object System.Data.OleDb.OleDbConnection($connectstring) 
    $OLEDBConn.open() 
    $readcmd = New-Object system.Data.OleDb.OleDbCommand($sql,$OLEDBConn) 
    $readcmd.CommandTimeout = '300' 
    $da = New-Object system.Data.OleDb.OleDbDataAdapter($readcmd) 
    $dt = New-Object System.Data.DataTable 
    [void]$da.fill($dt) 
    $OLEDBConn.close() 
    return $dt 
} 

if ($eventcheck) 
    { 
     $output = Get-OLEDBData $connString $qry1 
     ForEach ($lines in $output) 
     { 
      start-process -NoNewWindow -FilePath msend.exe -ArgumentList @" 
       -n bem_snmp01 -r CRITICAL -a CSG_VANTAGE_PLUS -m "The report $($lines.RPT) for site $($lines.SITE) has not been loaded by $($lines.EXPDTE)" -b "vp_reportnumber='$($lines.RPT)'; vp_sitename='$($lines.SITE)'; vp_expectedcomplete='$($lines.SIMEXPECTED)'; csg_environment='Production';" 
"@ # KEEP THIS TERMINATOR AT THE BEGINNING OF LINE  
     } 
    } 

if ($statuscheck) 
    { 
     $output = Get-OLEDBData $connString $qry2 
     # $output | foreach {$_.completed} 
     write-host -nonewline $output.completed 
    } 

所以,你可以看到的數據,下面是從Oracle SQL Developer中輸出的csv與實際結果正由我的腳本引用的查詢。在這些結果中,第4,5,6,7,8,10行是ForEach循環中唯一傳遞的行,而其他行甚至沒有在$ output數組中捕獲。如果任何人都可以建議一種方法來獲得所有的結果,我將不勝感激。

"SITE","RPT","LSDTE","EXPDTE","CIMEXPECTED","EXPECTED_FREQUENCY","DATE_TIMING","ETME" 
"chrcse","CPHM-054","","2014/09/21 12:00:00","20140921120000","MONTHLY","1", 
"chrcse","CPSM-226","","2014/09/21 12:00:00","20140921120000","MONTHLY","1", 
"dsh","CPSD-176","2014/09/28 23:20:04","2014/09/30 04:00:00","20140930040000","DAILY","1",1.41637731481481481481481481481481481481 
"dsh","CPSD-178","2014/09/28 23:20:11","2014/09/30 04:00:00","20140930040000","DAILY","1",1.4162962962962962962962962962962962963 
"exp","CPSM-610","2014/08/22 06:42:10","2014/09/21 09:00:00","20140921090000","MONTHLY","1",39.10936342592592592592592592592592592593 
"mdc","CPKD-264","2014/09/24 00:44:32","2014/09/30 04:00:00","20140930040000","DAILY","1",6.35771990740740740740740740740740740741 
"nea","CPKD-264","2014/09/24 01:00:31","2014/09/30 03:00:00","20140930030000","DAILY","1",6.34662037037037037037037037037037037037 
"twtla","CPOD-034","","2014/09/29 23:00:00","20140929230000","DAILY","0", 
"twtla","CPPE-002","2014/09/29 02:40:35","2014/09/30 06:00:00","20140930060000","DAILY","1",1.27712962962962962962962962962962962963 
"twtla","CPXX-004","","2014/09/29 23:00:00","20140929230000","DAILY","0", 
+1

您正在SQL Developer的本地'vantageplus_processing.sql'中運行完全相同的(已提交)數據 - 您不僅在該會話中有未提交的數據?也許表明SQL可能會揭示一些東西。 'fill'是否返回添加到數據表中的行數,如果是,那麼它在那個點上看到11行? – 2014-09-30 16:34:05

+0

我會添加SQL,不知何故,它使我超過了像16k允許的最大字符數。至於承諾或不承諾,我不知道如何說,我不管理數據庫,但我會做一些研究,看看我能否弄清楚。 – billhubb84 2014-09-30 17:05:17

+1

那麼,你是否通過SQL Developer創建了任何缺失的行?如果您在新會話中運行查詢(可能是不同的客戶端; SQL * Plus,Toad等等;或者如果SQL Developer設置爲共享工作表之間的連接/會話,則斷開連接並重新連接),您是否看到空?或者只是在SQL Developer中進行提交,當然,只要您確定要保留所有未完成的更改即可。 – 2014-09-30 17:09:53

回答

1

它的出現,實際上,這在某種程度上,這是在查詢中的註釋是造成這個問題。我刪除它,結果開始恢復正常。我不知道爲什麼會出現這種情況,除非它與導入方式有關(它是否將所有內容導入爲一行?)。無論哪種方式,結果現在都是正常的。

+0

我會在2天內接受這個答案。 – billhubb84 2014-09-30 18:05:02