weixin_39711849 2017-08-03 01:37 采纳率: 0%
浏览 2695

编写sql语句数据库当前年份,以及往后推5年的年份,咋写,下面这两种sql不行

select to_char(sysdate,'yyyy') from dual
union
select to_char(sysdate-365,'yyyy') from dual
union
select to_char(sysdate-365*2,'yyyy') from dual
union
select to_char(sysdate-365*3,'yyyy') from dual
union
select to_char(sysdate-365*4,'yyyy') from dual
union
select to_char(sysdate-365*5,'yyyy') from dual
union
select to_char(sysdate+365,'yyyy') from dual
union
select to_char(sysdate+365*2,'yyyy') from dual
union
select to_char(sysdate+365*3,'yyyy') from dual
union
select to_char(sysdate+365*4,'yyyy') from dual
union
select to_char(sysdate+365*5,'yyyy') from dual
网上看的

select extract(year from sysdate) from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) -1 from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) -2 from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) -3 from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) -4 from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) -5 from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) +1 from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) +2 from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) +3 from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) +4 from BO_ACT_MES_SECMAINTENANCE
union
select extract(year from sysdate) +5 from BO_ACT_MES_SECMAINTENANCE

  • 写回答

2条回答 默认 最新

  • 丵鹰 2017-08-03 01:59
    关注

    超过2个sql需要使用union all

    select to_char("ADD_MONTHS"(sysdate, c12),'yyyy') from dual
    union all
    select to_char("ADD_MONTHS"(sysdate, 1*12),'yyyy') from dual
    union all
    select to_char("ADD_MONTHS"(sysdate, 2*12),'yyyy') from dual

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler