2012-08-29 66 views
2

我試圖插入一條記錄到Oracle數據庫,代碼如下: 我得到ORA-00936:ORA-00936:缺少表達vb.net - 甲骨文

缺少表達的點心t1 As Integer = cmd3.ExecuteNonQuery()。

我檢查了3次,我確定我不會丟失任何變量。請幫忙! :(

Dim cmd3 As New OracleCommand 
       cmd3.Connection = conn 
       Dim timepara As String = Now.Hour & Now.Minute & Now.Second & Now.Millisecond 
       cmd3.CommandText = "INSERT INTO d009040 (LBRCODE,ENTRYDATE,BATCHCD,SETNO,SCROLLNO,MAINSCROLLNO,POSTDATE,FEFFDATE,ACTIVITYTYPE,CASHFLOWTYPE,VALUEDATE,BOOKTYPE,DRCR,VCRACCTID,MAINACCTID,MAINMODTYPE,VCRMODTYPE,TRNCURCD,FCYTRNAMT,LCYCONVRATE,LCYTRNAMT,INSTRBANKCD,INSTRBRANCHCD,INSTRTYPE,INSTRNO,INSTRDATE,TOKENNO,PARTICULARS,SYSGENVCR,SHTOTFLAG,SHCLRFLAG,ACTOTFLAG,ACCLRFLAG,MAKER,MAKERDATE,MAKERTIME,CHECKER1,CHECKER2,CHECKER3,CHECKER4,CHECKERDATE,CHECKERTIME,NOAUTHPENDING,NOAUTHOVER,POSTFLAG,AUTHFLAG,FEFFFLAG,CANCELEDFLAG,POSTAUTHFEFFCNCL,UPDTCHKID,PARTCLEARAMT,POSTTIME) VALUES (@LBRCODE,@ENTRYDATE,@BATCHCD,@SETNO,@SCROLLNO,@MAINSCROLLNO,@POSTDATE,@FEFFDATE,@ACTIVITYTYPE,@CASHFLOWTYPE,@VALUEDATE,@BOOKTYPE,@DRCR,@VCRACCTID,@MAINACCTID,@MAINMODTYPE,@VCRMODTYPE,@TRNCURCD,@FCYTRNAMT,@LCYCONVRATE,@LCYTRNAMT,@INSTRBANKCD,@INSTRBRANCHCD,@INSTRTYPE,@INSTRNO,@INSTRDATE,@TOKENNO,@PARTICULARS,@SYSGENVCR,@SHTOTFLAG,@SHCLRFLAG,@ACTOTFLAG,@ACCLRFLAG,@MAKER,@MAKERDATE,@MAKERTIME,@CHECKER1,@CHECKER2,@CHECKER3,@CHECKER4,@CHECKERDATE,@CHECKERTIME,@NOAUTHPENDING,@NOAUTHOVER,@POSTFLAG,@AUTHFLAG,@FEFFFLAG,@CANCELEDFLAG,@POSTAUTHFEFFCNCL,@UPDTCHKID,@PARTCLEARAMT,@POSTTIME)" 
       'myCommand.Parameters[0].Value = 60; 
       ''110','15-MAR-12','TR-MOBDS','5','5','5','15-MAR-12','15-MAR-12','CR','CR','15-MAR-12','ZZ','C','DS  000000000000240700000000','DS  000000000000240700000000','47','47','INR','100','1','100','0','0','99','000000000000','15-MAR-12','0','DDS CR. From Agent','1','Y','Y','Y','Y','0','15-MAR-12','12203130','0','0','0','0','15-MAR-12','12203130','0','1','P','A','F','0','0','0','0','12203130')" 
       cmd3.Prepare() 
       datepara = Date.Now.ToString("dd-MMM-yy") 
       'myCommand1.Parameters.Add("deptno", 20) 
       cmd3.Parameters.Add("@LBRCODE", lbr) 
       cmd3.Parameters.Add("@ENTRYDATE", datepara) 
       cmd3.Parameters.Add("@BATCHCD", "TR-MOBDS") 
       cmd3.Parameters.Add("@SETNO", k) 
       cmd3.Parameters.Add("@SCROLLNO", k) 
       cmd3.Parameters.Add("@MAINSCROLLNO", k) 'VALUEDATE,BOOKTYPE,DRCR,VCRACCTID,MAINACCTID,MAINMODTYPE,VCRMODTYPE,TRNCURCD,FCYTRNAMT, 
       cmd3.Parameters.Add("@POSTDATE", datepara) 
       cmd3.Parameters.Add("@FEFFDATE", datepara) 
       cmd3.Parameters.Add("@ACTIVITYTYPE", "CR") 
       cmd3.Parameters.Add("@CASHFLOWTYPE", "CR") 
       cmd3.Parameters.Add("@VALUEDATE", datepara) 
       cmd3.Parameters.Add("@BOOKTYPE", "ZZ") 
       cmd3.Parameters.Add("@DRCR", "C") 'LCYCONVRATE,LCYTRNAMT,INSTRBANKCD,INSTRBRANCHCD,INSTRTYPE,INSTRNO,INSTRDATE,TOKENNO, 
       cmd3.Parameters.Add("@VCRACCTID", internalaccount) 
       cmd3.Parameters.Add("@MAINACCTID", internalaccount) 
       cmd3.Parameters.Add("@MAINMODTYPE", "47") 
       cmd3.Parameters.Add("@VCRMODTYPE", "47") 
       cmd3.Parameters.Add("@TRNCURCD", "INR") 
       cmd3.Parameters.Add("@FCYTRNAMT", amount) 
       cmd3.Parameters.Add("@LCYCONVRATE", "1") 
       cmd3.Parameters.Add("@LCYTRNAMT", amount) 
       cmd3.Parameters.Add("@INSTRBANKCD", "0") 
       cmd3.Parameters.Add("@INSTRBRANCHCD", "0") 
       cmd3.Parameters.Add("@INSTRTYPE", "99") 
       cmd3.Parameters.Add("@INSTRNO", "000000000000") 
       cmd3.Parameters.Add("@INSTRDATE", datepara) 
       cmd3.Parameters.Add("@TOKENNO", "0") 'PARTICULARS,SYSGENVCR,SHTOTFLAG,SHCLRFLAG,ACTOTFLAG,ACCLRFLAG,MAKER,MAKERDATE,MAKERTIME, 
       cmd3.Parameters.Add("@PARTICULARS", "DDS CR. From Agent") 
       cmd3.Parameters.Add("@SYSGENVCR", "1") 
       cmd3.Parameters.Add("@SHTOTFLAG", "Y") 
       cmd3.Parameters.Add("@SHCLRFLAG", "Y") 
       cmd3.Parameters.Add("@ACTOTFLAG", "Y") 
       cmd3.Parameters.Add("@ACCLRFLAG", "Y") 
       cmd3.Parameters.Add("@MAKER", "0") 'CHECKER1,CHECKER2,CHECKER3,CHECKER4,CHECKERDATE,CHECKERTIME,NOAUTHPENDING, 
       cmd3.Parameters.Add("@MAKERDATE", datepara) 
       cmd3.Parameters.Add("@MAKERTIME", Now.Hour & Now.Minute & Now.Second & Now.Millisecond) 
       cmd3.Parameters.Add("@CHECKER1", "0") 
       cmd3.Parameters.Add("@CHECKER2", "0") 
       cmd3.Parameters.Add("@CHECKER3", "0") 
       cmd3.Parameters.Add("@CHECKER4", "0") 'NOAUTHOVER,POSTFLAG,AUTHFLAG,FEFFFLAG,CANCELEDFLAG,POSTAUTHFEFFCNCL,UPDTCHKID,PARTCLEARAMT,POSTTIME 
       cmd3.Parameters.Add("@CHECKERDATE", datepara) 
       cmd3.Parameters.Add("@CHECKERTIME", Now.Hour & Now.Minute & Now.Second & Now.Millisecond) 
       cmd3.Parameters.Add("@NOAUTHPENDING", "0") 
       cmd3.Parameters.Add("@NOAUTHOVER", "1") 
       cmd3.Parameters.Add("@POSTFLAG", "P") 
       cmd3.Parameters.Add("@AUTHFLAG", "A") 
       cmd3.Parameters.Add("@FEFFFLAG", "F") 
       cmd3.Parameters.Add("@CANCELEDFLAG", " ") 'UPDTCHKID,PARTCLEARAMT,POSTTIME 
       cmd3.Parameters.Add("@POSTAUTHFEFFCNCL", "0") 
       cmd3.Parameters.Add("@UPDTCHKID", "0") 
       cmd3.Parameters.Add("@PARTCLEARAMT", "0") 
       cmd3.Parameters.Add("@POSTTIME", Now.Hour & Now.Minute & Now.Second & Now.Millisecond) 



       Dim str As String = cmd3.CommandText 
       cmd3.CommandType = CommandType.Text 
       Try 
        Dim t1 As Integer = cmd3.ExecuteNonQuery() 
       Catch ex As Exception 
        msg(ex.ToString) 
       End Try 

回答

4

正如我已經表明我的previous question甲骨文對參數比SQL-Server的一個不同的語法,因此使用:而不是@

例如:

Using con = New OracleConnection(connectionString) 
    Dim sql = "INSERT INTO d009040 (LBRCODE,ENTRYDATE,BATCHCD,SETNO,SCROLLNO,MAINSCROLLNO,POSTDATE,FEFFDATE,ACTIVITYTYPE,CASHFLOWTYPE,VALUEDATE,BOOKTYPE,DRCR,VCRACCTID,MAINACCTID,MAINMODTYPE,VCRMODTYPE,TRNCURCD,FCYTRNAMT,LCYCONVRATE,LCYTRNAMT,INSTRBANKCD,INSTRBRANCHCD,INSTRTYPE,INSTRNO,INSTRDATE,TOKENNO,PARTICULARS,SYSGENVCR,SHTOTFLAG,SHCLRFLAG,ACTOTFLAG,ACCLRFLAG,MAKER,MAKERDATE,MAKERTIME,CHECKER1,CHECKER2,CHECKER3,CHECKER4,CHECKERDATE,CHECKERTIME,NOAUTHPENDING,NOAUTHOVER,POSTFLAG,AUTHFLAG,FEFFFLAG,CANCELEDFLAG,POSTAUTHFEFFCNCL,UPDTCHKID,PARTCLEARAMT,POSTTIME) VALUES (:LBRCODE,:ENTRYDATE,:BATCHCD,:SETNO,:SCROLLNO,:MAINSCROLLNO,:POSTDATE,:FEFFDATE,:ACTIVITYTYPE,:CASHFLOWTYPE,:VALUEDATE,:BOOKTYPE,DRCR,:VCRACCTID,:MAINACCTID,:MAINMODTYPE,:VCRMODTYPE,:TRNCURCD,:FCYTRNAMT,:LCYCONVRATE,:LCYTRNAMT,:INSTRBANKCD,:INSTRBRANCHCD,:INSTRTYPE,:INSTRNO,:INSTRDATE,:TOKENNO,:PARTICULARS,:SYSGENVCR,:SHTOTFLAG,:SHCLRFLAG,:ACTOTFLAG,:ACCLRFLAG,:MAKER,:MAKERDATE,:MAKERTIME,:CHECKER1,:CHECKER2,:CHECKER3,:CHECKER4,:CHECKERDATE,:CHECKERTIME,:NOAUTHPENDING,:NOAUTHOVER,:POSTFLAG,:AUTHFLAG,:FEFFFLAG,:CANCELEDFLAG,:POSTAUTHFEFFCNCL,:UPDTCHKID,:PARTCLEARAMT,:POSTTIME)" 
    Using cmd = New OracleCommand(sql, con) 
     con.Open() 
     cmd.Parameters.AddWithValue(":LBRCODE", LBRCODE) 
     ' add the other parameters as well ... ' 
     dim result = cmd.ExecuteNonQuery() 
    End Using 
End Using 

在由CommandType.Text的OracleCommand調用的SQL語句中使用命名參數時,必須在參數名稱前加冒號(:)。

http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oraclecommand.parameters.aspx

+0

我嘗試過:早些時候,然後@ – user1051505

+0

@ user1051505:你用冒號得到了什麼異常? –

+0

當我使用時,我得到了ex = {「ORA-00928:missing SELECT keyword」}: – user1051505