【问题标题】:Oracle ORA-01036 illegal variable name/number for no obvious reasonOracle ORA-01036 无明显原因的非法变量名称/编号
【发布时间】:2014-09-01 07:37:57
【问题描述】:

我创建了一个从 ASP.NET Web 表单中的网页调用的 INSERT 语句

当我尝试执行查询时,我得到了这个:ORA-01036 非法变量名称/编号。不幸的是,我只有对数据库本身的只读访问权限,所以我无法测试他们的查询,因为它很寂寞。下面是我的整个方法,因为我不确定问题出在查询中还是在参数中。

 public static String InsertIntoMiscReceiptCashTable(
    String Payeedetail,String LocationCode, 
    String TransactionDate, String CashBookstoreCode, 
    String CashBookstoreSalesTaxCode, 
    String CashOther1DDL, String CashOther2DDl, 
    String CashOther1CommentTxt, String CashOther2CommentTxt,
    String CashCommentTxtBx, String RecapCashCommentTxtBx, 
    String RecapCheckNumCommentTxtBx,
    String RecapTotalCommentTxtBx, String RecapPymtRcvdCommentTxtBx, 
    String RecapChangeCommentTxtBx,
    String SysUserName, Double CashBookstoreAmountTxtBx, 
    Double CashBookstoreSalesTaxAmountTxtBx,
    Double CashOther1AmountTxtBx, Double CashOther2AmountTxtBx, 
    Double RecapCashAmountTxtBx,
    Double RecapCheckNumAmountTxtBx, Double RecapPymtRcvdAmountTxtBx, 
    Double RecapChangeAmountTxtBx,
    Double RecapTotalAmountTxtBx, Double CashTotalPaymentAmountTxtBx
    )
{
        DbLastKeySequence.addLastKeySequence("MISCRECEIPTSCASH.MISCRECEIPTID");
        int MiscReceiptID_lastKeySequence = 
          Convert.ToInt32(DbLastKeySequence.findLastKeySequence("MISCRECEIPTSCASH.MISCRECEIPTID"));

        String NextBatchNumber = ""; String NextReceiptNumber = "";
        DataTable NextValues = 
         DbCashMiscReceiptPg.Get_Description_NextBatchNum_NextReceiptNum(LocationCode);
        DataTableReader reader = NextValues.CreateDataReader();
        while (reader.Read())
        {
            NextBatchNumber = (reader["NEXTBATCHNUMBER"].ToString());
            NextReceiptNumber = (reader["NEXTRECEIPTNUMBER"].ToString());
        }
        reader.Close();

        String CommandText = "INSERT INTO MISCRECEIPTSCASH ( " + 
            "MISCRECEIPTID, " +
            "PAYEENAME, " +
            "TRANSACTIONDATE, " +
            "BATCHNUMBER, " +
            "RECEIPTNUMBER, " +
            "VOIDINDICATOR, " +
            "CASHTYPEPMTCODE1, " +
            "CASHCODE1, " +
            "CASHBOOKSTORECODE, " +
            "CASHSALESTAXCODE, " +
            "CASHOTHERCODE1, " +
            "CASHOTHERCODE2, " +
            "CASHOTHERCOMMENT1, " +
            "CASHOTHERCOMMENT2, " +
            "CHARGEBOOKSTORECODE, " +
            "LOCATIONCODE, " +
            "CASHCOMMENT, " +
            "RECAPCASHCOMMENT, " + 
            "RECAPCHECK1COMMENT, " +
            "RECAPTOTALCOMMENT, " +
            "RECAPPYMTRCVDCOMMENT," +
            "RECAPCHANGECOMMENT, " +
            "INITIALS, " +
            "CASHPAYMENTONACCOUNT1, " +
            "CASHPAYMENTONACCOUNT2, " +
            "CASHBOOKSTORE, " +
            "CASHSALESTAX, " +
            "CASHOTHERAMOUNT1," + 
            "CASHOTHERAMOUNT2, " +
            "CHARGEBOOKSTORE, " +
            "CHARGESALESTAX, " +
            "CHARGEOTHERAMOUNT, " +
            "RECAPCASHAMOUNT, " +
            "RECAPCHECK1AMOUNT,  " +
            "RECAPPYMTRCVDAMOUNT, " +
            "CHANGEAMT, " +
            "TOTALCHARGES, " +
            "TOTALRECAP, " +
            "TOTALPAYMENT, " +
            "GENERATEASCII, " +
            "GENERATEDDATE" +
            ")";

        CommandText += "VALUES ( " +
            ":MISCRECEIPTID, " +
            "':PayeeDetails', " +
            "TO_DATE(:TransactionDate,'yyyy-mm-dd HH24:MI:SS'), " +
            "':BatchNumber', " +
            "':ReceiptNumber', " +
            "'N', " +
            "'01', " +
            "'00012500', " +
            "':CashBookstoreCode', " +
            "':CashBookstoreSalesTaxCode', " +
            "':CashOther1DDL', " +
            "':CashOther2DDL', " +
            "':CashOther1CommentTxt'," +
            "':CashOther2CommentTxt'," +
            "':CashBookstoreCode', " +
            "':LocationCode', " +
            "':CashCommentTxtBx'," + 
            "':RecapCashCommentTxtBx'," + 
            "':RecapCheckNumCommentTxtBx'," + 
            "':RecapTotalCommentTxtBx'," +
            "':RecapPymtRcvdCommentTxtBx'," +
            "':RecapChangeCommentTxtBx'," +
            "':SysUserName'," +
            "0," +
            "0," +
            ":CashBookstoreAmountTxtBx," + 
            ":CashBkstreSalesTaxAmountTxtBx," + 
            ":CashOther1AmountTxtBx," +
            ":CashOther2AmountTxtBx," +
            "0, " +
            "0, " +
            "0, " +
            ":RecapCashAmountTxtBx, " +
            ":RecapCheckNumAmountTxtBx, " +
            ":RecapPymtRcvdAmountTxtBx," +
            ":RecapChangeAmountTxtBx," +
            "0, " +
            ":RecapTotalAmountTxtBx, " +
            ":CashTotalPaymentAmountTxtBx, " +
            "'N', " +
            "TO_DATE(:TransactionDate,'yyyy-mm-dd HH24:MI:SS') " +
            ")";

        cmd = new OracleCommand(CommandText, con);
        cmd.CommandType = CommandType.Text;

        cmd.Parameters.Clear();

        cmd.Parameters.AddWithValue(":MISCRECEIPTID", MiscReceiptID_lastKeySequence);
        cmd.Parameters.AddWithValue(":PayeeDetails", Payeedetail);
        cmd.Parameters.AddWithValue(":TransactionDate", TransactionDate);
        cmd.Parameters.AddWithValue(":BatchNumber", NextBatchNumber);
        cmd.Parameters.AddWithValue(":ReceiptNumber", NextReceiptNumber);
        cmd.Parameters.AddWithValue(":CashBookstoreCode", CashBookstoreCode); // Same as down there
        cmd.Parameters.AddWithValue(":CashBookstoreSalesTaxCode", CashBookstoreSalesTaxCode);
        cmd.Parameters.AddWithValue(":CashOther1DDL", CashOther1DDL);
        cmd.Parameters.AddWithValue(":CashOther2DDL", CashOther2DDl);
        cmd.Parameters.AddWithValue(":CashOther1CommentTxt", CashOther1CommentTxt);
        cmd.Parameters.AddWithValue(":CashOther2CommentTxt", CashOther2CommentTxt);
        //cmd.Parameters.AddWithValue(":CashBookstoreCode", CashBookstoreCode); // Same as up there 
        cmd.Parameters.AddWithValue(":LocationCode", LocationCode);
        cmd.Parameters.AddWithValue(":CashCommentTxtBx", CashCommentTxtBx);
        cmd.Parameters.AddWithValue(":RecapCashCommentTxtBx", RecapCashCommentTxtBx);
        cmd.Parameters.AddWithValue(":RecapCheckNumCommentTxtBx", RecapCheckNumCommentTxtBx);
        cmd.Parameters.AddWithValue(":RecapTotalCommentTxtBx", RecapTotalCommentTxtBx);
        cmd.Parameters.AddWithValue(":RecapPymtRcvdCommentTxtBx", RecapPymtRcvdCommentTxtBx);
        cmd.Parameters.AddWithValue(":RecapChangeCommentTxtBx", RecapChangeCommentTxtBx);
        cmd.Parameters.AddWithValue(":SysUserName", SysUserName);
        cmd.Parameters.AddWithValue(":CashBookstoreAmountTxtBx", CashBookstoreAmountTxtBx);
        cmd.Parameters.AddWithValue(":CashBkstreSalesTaxAmountTxtBx", CashBookstoreSalesTaxAmountTxtBx);
        cmd.Parameters.AddWithValue(":CashOther1AmountTxtBx", CashOther1AmountTxtBx);
        cmd.Parameters.AddWithValue(":CashOther2AmountTxtBx", CashOther2AmountTxtBx);
        cmd.Parameters.AddWithValue(":RecapCashAmountTxtBx", RecapCashAmountTxtBx);
        cmd.Parameters.AddWithValue(":RecapCheckNumAmountTxtBx", RecapCheckNumAmountTxtBx);
        cmd.Parameters.AddWithValue(":RecapPymtRcvdAmountTxtBx", RecapPymtRcvdAmountTxtBx);
        cmd.Parameters.AddWithValue(":RecapChangeAmountTxtBx", RecapChangeAmountTxtBx);
        cmd.Parameters.AddWithValue(":RecapTotalAmountTxtBx", RecapTotalAmountTxtBx);
        cmd.Parameters.AddWithValue(":CashTotalPaymentAmountTxtBx", CashTotalPaymentAmountTxtBx);

        con.Open();
        cmd.ExecuteNonQuery();

        cmd.Parameters.Clear();

        con.Close();
        return NextReceiptNumber;

}// end db insert query

我检查了所有列的名称 - 它们都是正确的。我还检查了所有参数名称(复制和粘贴),它们都是正确的(除非我发疯了)。我还检查了所有这些的数据类型 - 一切都很好。在设置参数值时,我还去掉了所有参数的冒号 (:),但仍然出现错误。

如果有人对我为什么不断收到此错误有任何想法,我们将不胜感激。

【问题讨论】:

    标签: asp.net sql oracle insert


    【解决方案1】:

    不确定这是否是您的错误的原因,但参数占位符肯定不应该用单引号括起来。这样它们就变成了文字字符串

    例如(但不仅如此)

     "':BatchNumber', " 
    

    应该是

     ":BatchNumber, "
    

    【讨论】:

    • 完美解决了!!非常感谢
    猜你喜欢
    • 2013-01-06
    • 2011-10-05
    • 1970-01-01
    • 2020-07-29
    • 2016-04-03
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多