我正在使用 .NET OracleClient(在 C# 中),并且我有一个查询返回的结果不正确(行数少于预期)。
这是我唯一一次看到这种情况发生。
我可以将查询剪切/粘贴到 SQl Developer 或 sql*plus 中,它会返回正确的 281 行。当它在 .NET 应用程序中运行时,数据表只有 280 个(我知道缺少哪条记录)。
有没有人见过这种情况发生或对为什么有任何想法?
这是C#代码
string llQuery = "select DISTINCT " +
"case when aliased_item = 'TIME SERIES' then 'TS_ALIAS' else 'TIME_SERIES' end data_type, " +
"cwms_ts_id " +
"from (select aliased_item, SUBSTR(cwms_ts_id, instr(cwms_ts_id, '.') + 1, LENGTH(cwms_ts_id) - instr(cwms_ts_id, '.')) cwms_ts_id " +
"from CWMS_V_TS_ID2) " +
"union all " +
"select DISTINCT 'LOCATION_LEVEL' data_type, cwms_ts_id " +
"from (select SUBSTR(location_level_id, instr(location_level_id, '.') + 1, LENGTH(location_level_id) - instr(location_level_id, '.')) cwms_ts_id " +
"from CWMS_V_LOCATION_LEVEL) " +
" order by data_type desc, cwms_ts_id";
try
{
OracleConnection connection_obj = new OracleConnection();
connection_obj.ConnectionString = connStr;
connection_obj.Open();
using (OracleCommand command = new OracleCommand())
{
command.Connection = connection_obj;
command.CommandType = CommandType.Text;
command.CommandText = llQuery;
DataTable dtLvl = new DataTable();
dtLvl.Load(command.ExecuteReader());
这是查询,它被复制/粘贴,字符“,+删除等。
select DISTINCT
case when aliased_item = 'TIME SERIES' then 'TS_ALIAS' else 'TIME_SERIES' end data_type,
cwms_ts_id
from (select aliased_item, SUBSTR(cwms_ts_id, instr(cwms_ts_id, '.') + 1, LENGTH(cwms_ts_id) - instr(cwms_ts_id, '.')) cwms_ts_id
from CWMS_V_TS_ID2)
union all
select DISTINCT 'LOCATION_LEVEL' data_type, cwms_ts_id
from (select SUBSTR(location_level_id, instr(location_level_id, '.') + 1, LENGTH(location_level_id) - instr(location_level_id, '.')) cwms_ts_id
from CWMS_V_LOCATION_LEVEL)
丢失的记录恰好是
data_type cwms_ts_id
========= ========================================
TS_ALIAS Code-ProjectStatus.Const.1Day.1Day.ALIAS
在应用程序中执行查询后,dtLvl.Rows.Count = 280 而不是 281,并且上面指示的记录不存在。
不知道下一步该去哪里寻找为什么会发生这种情况——正如我所提到的,我以前从未见过它发生过
感谢您的任何想法!