2

我正在尝试将一条记录插入到 oracle 数据库中,代码如下:我得到 ORA-00936:

在 Dim 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

1 回答 1

4

正如我在您之前的问题中所展示的那样,Oracle 的参数语法与 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

于 2012-08-29T11:48:16.997 回答