我想在oracle中实现这样一个查询,并返回结果集呢. 用视图还是存储过程呢.找出日期是今天的数据,如果没有今天的数据就要返回
和今天离的最近的一天的数据,怎么写呢。
我这个查询可以实现的,但是在在今天和距离今天最近的一天都有数据的时候都查询出来了.
select * from classinfo where curr_date =sysdate or curr_date = (select max(curr_date) from Rates where curr_date < sysdate);
和今天离的最近的一天的数据,怎么写呢。
我这个查询可以实现的,但是在在今天和距离今天最近的一天都有数据的时候都查询出来了.
select * from classinfo where curr_date =sysdate or curr_date = (select max(curr_date) from Rates where curr_date < sysdate);
解决方案 »
- 请教DRIVER={Microsoft ODBC for Oracle} 连接问题!
- 在线求一个SQL查询的方法!我想了2个小时都还弄不出来!
- 我用 PL/SQL developer 写存储过程时,当我输入dbms_out.put_line 时总是提示未连接到 oracle,但事实上我是连接到数据库的。为什么啊?
- plsql developer的使用方法
- 通过数据查询列名
- 远程登陆oracle
- 怎样用C#将数组传入Oralce的可变数组或者嵌套表?? 其他语言也可以参考
- oracle9i在win2003上安装的问题
- 二面,问了一个问题,被pass掉。
- oracle
- SQL求补集的问题,急~~~~
- 关于Oracle 约束问题
不行的话,写个存储过程来判断。
as
l_count number:=0;
begin
select count(*) into l_count from classinfo where curr_date >=to_date(sysdate,'yyyy-mm-dd') and curr_date <=to_date(sysdate+1,'yyyy-mm-dd');
if l_count =0 then
open p_cur for select * from classinfo where curr_date =(select max(curr_date) from classinfo);
else
open p_cur for select * from classinfo where curr_date >=to_date(sysdate,'yyyy-mm-dd') and curr_date <=to_date(sysdate+1,'yyyy-mm-dd');
end;
end;
exception
when NO_DATA_FOUND then
select * from Rates where curr_date = (select max(curr_date) from Rates where curr_date < to_date('2010-05-09','YYYY-MM-DD') );
end;我猜大概可能这样的.
你在java中捕获异常后除了打异常日志,抛出异常外,还进行过业务逻辑的处理???
select * from classinfo c1 where not exists (select 1 from classinfo where curr_date>c.curr_date);
不知楼主的rates是什么表,有什么关系
不过这里需要curr_date不包含hhmmss