SQL命令未正确结束异常 [英] SQL Command not properly ended Exception

查看:472
本文介绍了SQL命令未正确结束异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Pretty basic sql Command. Just want to get the count from different tables I am looping through. However, if I alter the sqlCommand and add a ';' at the end I get exception, SQL command not properly ended.

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

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

I am curious why this semi-colon makes this exception thrown since commands are suppose to end with a ';'

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

推荐答案

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

Semi colons are usually just used as a command terminator for interactive tools like sqlplus.

这篇关于SQL命令未正确结束异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆