吐槽前软件工程师写的查询语句,看得蛋疼
吐槽前程序员写的查询语句,看得蛋疼啊
就一个简单的条件语句,
不知大家看出问题了没?反正我是受不了这样的写法了
------解决方案--------------------
似乎一个 trunc 就够了。前几个没什么正经用吧。
------解决方案--------------------
这个 应该是对trunc函数不熟悉导致的吧。。
刚去搜了一下trunc的函数用法。 (我自己平常用的也是不加参数的)
1.select trunc(sysdate) from dual --2011-3-18 今天的日期为2011-3-18
2.select trunc(sysdate, 'mm') from dual --2011-3-1 返回当月第一天.
3.select trunc(sysdate,'yy') from dual --2011-1-1 返回当年第一天
4.select trunc(sysdate,'dd') from dual --2011-3-18 返回当前年月日
5.select trunc(sysdate,'yyyy') from dual --2011-1-1 返回当年第一天
6.select trunc(sysdate,'d') from dual --2011-3-13 (星期天)返回当前星期的第一天
7.select trunc(sysdate, 'hh') from dual --2011-3-18 14:00:00 当前时间为14:41
8.select trunc(sysdate, 'mi') from dual --2011-3-18 14:41:00 TRUNC()函数没有秒的精
就一个简单的条件语句,
and addtime between to_date(to_char(add_months(trunc(sysdate),-1),'yyyy-mm'),'yyyy-mm')
and to_date(to_char(add_months(trunc(sysdate),1),'yyyy-mm'),'yyyy-mm')
不知大家看出问题了没?反正我是受不了这样的写法了
------解决方案--------------------
似乎一个 trunc 就够了。前几个没什么正经用吧。
------解决方案--------------------
这个 应该是对trunc函数不熟悉导致的吧。。
刚去搜了一下trunc的函数用法。 (我自己平常用的也是不加参数的)
1.select trunc(sysdate) from dual --2011-3-18 今天的日期为2011-3-18
2.select trunc(sysdate, 'mm') from dual --2011-3-1 返回当月第一天.
3.select trunc(sysdate,'yy') from dual --2011-1-1 返回当年第一天
4.select trunc(sysdate,'dd') from dual --2011-3-18 返回当前年月日
5.select trunc(sysdate,'yyyy') from dual --2011-1-1 返回当年第一天
6.select trunc(sysdate,'d') from dual --2011-3-13 (星期天)返回当前星期的第一天
7.select trunc(sysdate, 'hh') from dual --2011-3-18 14:00:00 当前时间为14:41
8.select trunc(sysdate, 'mi') from dual --2011-3-18 14:41:00 TRUNC()函数没有秒的精