我正在使用.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, 并且上述记录不存在。
在接下来看看为什么会发生这种情况时不知所措 - 正如我所提到的,我从来没有见过它
感谢任何想法!