OracleDataAdapter.Fill抛出“SQL命令未正确结束”

时间:2015-04-17 16:12:59

标签: c# oracle plsql ado.net

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 个答案:

答案 0 :(得分: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语句末尾的分号,它应该可以工作。