我象实现的功能是:
如果现在的时间是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;

解决方案 »

  1.   

    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句语句本身就是错误的
      

  2.   

    date型的还to-date就是错的
      

  3.   

    那么如果将
    select to_date(sysdate,'yyyy') from dual
    select to_date(sysdate,'yyyy-mm') from dual
    select to_date(sysdate,'yyyy-mm-dd') from dual
    换成
    select to_char(sysdate,'yyyy-mm-dd') from dual
    select to_char(sysdate,'yyyy-mm-dd hh24') from dual
    select to_char(sysdate,'yyyy-mm-dd hh24:mi') from dual
    可以吗?
      

  4.   

    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;
      

  5.   

    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;
      

  6.   

    select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
    单独这样执行可以如果在pl\sql段中,要加 into
    declare aaa date;
    begin
    select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')  into aaa from dual;end;
      

  7.   

    如果是条件选择的话,是否只能写成是存储过程格式啊?
    我在机械工业出版社出的“Oracle9I初学者指南”中看到上门的例子也只有存储过程。