SQL命令未正确结束异常

时间:2017-03-16 18:24:38

标签: sql oracle

非常基本的sql命令。只是想从我正在循环的不同表中获取计数。但是,如果我改变了sqlCommand并添加了&#39 ;;'最后我得到异常,SQL命令没有正确结束。

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

我很好奇为什么这个分号会抛出这个异常,因为命令假设以&#39 ;;'

结束
 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()));
        }
     }

1 个答案:

答案 0 :(得分:0)

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