我正嘗試使用Powershell腳本對Oracle數據庫執行插入操作。這種方法適用於選擇查詢,但是對於插入它會給出錯誤。我閱讀了很多Stack Overflow帖子和各種其他網站,並嘗試過各種方法,但沒有一個能夠工作。ORA-00917在Powershell中缺少逗號
我該如何調試?我不是Powershell的專家。我很確定這個SQL有一些問題。
Add-Type -Path "P:\Home\Full Oracle\ora11g_x86\odp.net\bin\2.x\Oracle.DataAccess.dll"
try
{
$compConStr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=**)(PORT=1552)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=**)));User Id=**;Password=**;"
$oraConn= New-Object Oracle.DataAccess.Client.OracleConnection($compConStr)
$sid = "0001"
$region = "CH"
$timestamp = "2017-04-20 14:14:00"
$dep = "17-04-2017"
$scenario = "A"
$milestone = "ASB_XREF_GLCC_LOAD_2ND_END_E"
$finishtime = "2017-04-18/11:11"
$sql = "INSERT INTO APP_PDM_MART.PDM_GEAR_KPI_REP_SNOW(ST_ID,PRIORITY,STATUS,ACTIVE,ACTIVITY_DUE,ADD_REPORTED_BY,BUSINESS_CRITICALITY) VALUES($sid,$region,$timestamp,$dep,$scenario,$milestone,$finishtime)"
$oraConn.Open()
$command = New-Object Oracle.DataAccess.Client.OracleCommand($sql,$oraConn)
$tx = $oraConn.BeginTransaction()
$command.ExecuteNonQuery()
非常感謝。這解決了這個問題。我認爲Oracle必須寫出更好的錯誤。我在這方面掙扎如此之多。只有在隨機測試後,我才意識到問題在於傳遞的數據。儘管我在某處傳遞字符串,但是通過在其下面明確添加它的工作,它被錯誤地自動鑄造。 '$ finishtime = $參數[6]' '$ finishtime =''$ finishtime'「' –