3

我正在尝试使用 C# 从我的 Oracle 数据库 BY DATE 中选择数据。但是我总是得到一个空数据集,尽管相同的查询字符串在 Oracle SQL Developer 中工作得很好

String Query = "Select position_date from position";
OracleDataAdapter adapter = new OracleDataAdapter(Query, ocon); 
adapter.Fill(ds, "table"); //where ds is a dataset 
PrintDataSet(ds);

返回

3/8/2011 12:00:00 AM.... and more

但是,当我将查询更改为以下时,就没有输出了!

String Query = "Select position_date from position 
where to_char(position_date, 'mm-dd-yyyy') = '05-17-2012'"

此查询在 oracle sql developer 中运行良好。我也尝试过 trunc(sysdate) 但似乎没有任何效果!:(

4

2 回答 2

1
select * from position where trunc(position_date) = to_date('05-17-2012', 'mm-dd-yyyy')

工作。

谢谢。

于 2012-05-18T13:11:20.453 回答
0

如果您的日期没有时间部分(如果是这样,那么用检查约束来保证它),那么:

Select position_date
from   position 
where  position_date = date '2012-05-17'

否则:

Select position_date
from   position 
where  position_date >= date '2012-05-17' and 
       position_date <  date '2012-05-17' + 1
于 2012-05-18T08:05:23.900 回答