首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

在Oracle中的时间条件如何写啊

2012-03-13 
在Oracle中的时间条件怎么写啊?我象实现的功能是:如果现在的时间是8:00到16:00间执行语句selectto_date(sy

在Oracle中的时间条件怎么写啊?
我象实现的功能是:
如果现在的时间是8:00到16:00间
执行语句select   to_date(sysdate, 'yyyy ')   from   dual
如果现在的时间是16:00到00:00间
执行语句select   to_date(sysdate, 'yyyy-mm ')   from   dual
如果现在的时间是00:00到08:00间
执行语句select   to_date(sysdate, 'yyyy-mm-dd ')   from   dual
我写的这句老是有错误,也不知道错在哪里。
if   to_char(sysdate, 'hh24 ')   > =08   and   to_char(sysdate, 'hh24 ') <16   then
      select   to_date(sysdate, 'yyyy ')   from   dual;
elsif   to_char(sysdate, 'hh24 ')   > =16   and   to_char(sysdate, 'hh24 ') <00   then
      select   to_date(sysdate, 'yyyy-mm ')   from   dual;
elsif   to_char(sysdate, 'hh24 ')   > =00   and   to_char(sysdate, 'hh24 ') <08   then
      select   to_date(sysdate, 'yyyy-mm-dd ')   from   dual;
end   if;

[解决办法]
select to_date(sysdate, 'yyyy ') from dual
select to_date(sysdate, 'yyyy-mm ') from dual
select to_date(sysdate, 'yyyy-mm-dd ') from dual
3句语句本身就是错误的


[解决办法]
date型的还to-date就是错的

[解决办法]
if to_number(to_char(sysdate, 'hh24 ')) > =8 and to_char(to_char(sysdate, 'hh24 ')) <16 then
select to_date(sysdate, 'yyyy ') from dual;
elsif to_number(to_char(sysdate, 'hh24 ')) > =16 and to_number(to_char(sysdate, 'hh24 ')) <0 then
select to_date(sysdate, 'yyyy-mm ') from dual;
elsif to_number(to_char(sysdate, 'hh24 ')) > =0 and to_number(to_char(sysdate, 'hh24 ')) <8 then
select to_date(sysdate, 'yyyy-mm-dd ') from dual;
end if;

[解决办法]
select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss ') from dual;
单独这样执行可以

declare aaa date;
begin
select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss ') into aaa from dual;

end;

热点排行