OracleDataAdapter.Fill 抛出“SQL 命令未正确结束”
Posted
技术标签:
【中文标题】OracleDataAdapter.Fill 抛出“SQL 命令未正确结束”【英文标题】:OracleDataAdapter.Fill throws "SQL command not properly ended" 【发布时间】:2015-04-17 16:12:59 【问题描述】:OracleDataAdapter.Fill
抛出异常:“ORA-00933:SQL 命令未正确结束”。根据许多帖子,通常的罪魁祸首是末尾的一些空格或分号。我复制了语句并在Oracle“Sql Developer”上执行,它可以工作..
这是我的代码(有点)
var stmt = "SELECT fmly.fmly_id, fmly.fmly_key, fmly.fmly_db_view_nm, MI_DBUMS_UTIL.GET_BASELINE_TABLE_NAME(fmly.fmly_id) blTableName " +
"FROM mi_families AS fmly WHERE fmly.fmly_type_cd = 'ENFA' " +
"AND fmly.fmly_id not in (SELECT fmly_id from mi_exclude_families WHERE context_cd = 'REVERT') " +
"AND EXISTS " + "(SELECT 1 FROM mi_entities_bl AS enty_bl WHERE fmly.fmly_id = enty_bl.fmly_id);";
var conn = new OracleConnection("<connection string>");
var cmd = new OracleCommand(stmt, conn)
IDataAdapter adapter = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
conn.Open();
cmd.CommandTimeout = 0;
adapter.Fill(ds)
有人可以帮我解释引发异常的原因吗?
【问题讨论】:
去掉末尾引号内的分号并测试查询。 【参考方案1】:试试这个?
var stmt = "SELECT fmly.fmly_id, fmly.fmly_key, fmly.fmly_db_view_nm, MI_DBUMS_UTIL.GET_BASELINE_TABLE_NAME(fmly.fmly_id) blTableName " +
"FROM mi_families AS fmly WHERE fmly.fmly_type_cd = 'ENFA' " +
"AND fmly.fmly_id not in (SELECT fmly_id from mi_exclude_families WHERE context_cd = 'REVERT') " +
"AND EXISTS " + "(SELECT 1 FROM mi_entities_bl AS enty_bl WHERE fmly.fmly_id = enty_bl.fmly_id)";
var conn = new OracleConnection("<connection string>");
var cmd = new OracleCommand(stmt, conn);
IDataAdapter adapter = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
conn.Open();
cmd.CommandTimeout = 0;
adapter.Fill(ds);
删除 SELECT 语句末尾的分号,它应该可以工作。
【讨论】:
以上是关于OracleDataAdapter.Fill 抛出“SQL 命令未正确结束”的主要内容,如果未能解决你的问题,请参考以下文章
c# OracleDataAdapter.Fill 遇到不支持的 Oracle 数据类型