小编典典

SQL命令未正确结束异常

sql

相当基本的sql命令。只想从我正在遍历的不同表中获取计数。但是,如果我更改sqlCommand并添加“;” 最后我得到异常,SQL命令未正确结束。

     sqlCommand = String.Format("SELECT COUNT(1) FROM SO.{0} where DR_ADDRESS_ID = {1};", table, drAddr);

我很好奇为什么分号会引发此异常,因为命令应该以“;”结尾

 sqlCommand = String.Format("SELECT COUNT(1) FROM SO.{0} where DR_ADDRESS_ID = {1}", table, drAddr);
     try
     {      
        using(OracleCommand ocCommand = new OracleCommand(sqlCommand,CommandType.Text))
        {
           ocCommand.Connection = dbConnection;
           recordCounter = Convert.ToInt64(ocCommand.ExecuteScalar());
        }               
     }
     catch (Exception er)
     {
        MessageBox.Show(String.Format("Error in RecordCount for table {0}: Reference {1} for log. err = {2}",table, logFilePath,er.ToString()));
        recordCounter = -1;

        using (StreamWriter writer = new StreamWriter(logFilePath, true))
        {
           writer.WriteLine(String.Format("Table: {0}. Command {1}", table,sqlCommand.ToString()));
        }
     }

阅读 275

收藏
2021-04-14

共1个答案

小编典典

半冒号通常仅用作sqlplus等交互式工具的命令终止符。

2021-04-14