oracle时间段查询-从00:00:00开始

  之所以记录一下这篇博文,是因为前段时间搞的一个查询发现要从00:00:00这个时间段开始,必须要通过拼接字符串。

<select id="queryApplyProgressList" parameterType="java.util.Map" resultType="java.util.Map">
    SELECT T.*, U.USER_SINGLE_FEE
      FROM TAB_TAG_LEASE_APPLY T
    LEFT JOIN TAB_TAG_LEASE_USER U
    ON T.APPLY_USER_ID = U.USER_ID
     WHERE T.IS_DELETE = 0
       AND T.APPLY_USER_ID = #{userId,jdbcType=INTEGER}

    <if test="applyStatus != null">
      AND T.APPLY_STATUS=#{applyStatus,jdbcType=INTEGER}
    </if>
	<--3天内的记录-->
    <if test="three != null">
      AND T.CREATE_TIME <![CDATA[>=]]> TO_DATE(TO_CHAR(SYSDATE-3,'yyyy/mm/dd')||' 00:00:00','yyyy/mm/dd hh24:mi:ss')
      AND T.CREATE_TIME <![CDATA[<=]]> TO_DATE(#{listTime},'yyyy/mm/dd hh24:mi:ss')
    </if>
	<--7天内的记录-->
    <if test="seven != null">
      AND T.CREATE_TIME <![CDATA[>=]]> TO_DATE(TO_CHAR(SYSDATE-7,'yyyy/mm/dd')||' 00:00:00','yyyy/mm/dd hh24:mi:ss')
      AND T.CREATE_TIME <![CDATA[<=]]> TO_DATE(#{listTime},'yyyy/mm/dd hh24:mi:ss')
    </if>
	<--30天内的记录-->
    <if test="month != null">
      AND T.CREATE_TIME <![CDATA[>=]]> TO_DATE(TO_CHAR(SYSDATE-30,'yyyy/mm/dd')||' 00:00:00','yyyy/mm/dd hh24:mi:ss')
      AND T.CREATE_TIME <![CDATA[<=]]> TO_DATE(#{listTime},'yyyy/mm/dd hh24:mi:ss')
    </if>
	<--半年内的记录-->
    <if test="halfYear != null">
      AND T.CREATE_TIME <![CDATA[>=]]> TO_DATE(TO_CHAR(TRUNC(ADD_MONTHS(SYSDATE, -6)),'yyyy/mm/dd')||' 00:00:00','yyyy/mm/dd hh24:mi:ss')
      AND T.CREATE_TIME <![CDATA[<=]]> TO_DATE(#{listTime},'yyyy/mm/dd hh24:mi:ss')
    </if>
	<--当前年的记录-->
    <if test="year != null">
      AND TO_CHAR(T.CREATE_TIME, 'yyyy') = TO_CHAR(SYSDATE, 'yyyy')
    </if>
    ORDER BY T.CREATE_TIME DESC
  </select>

  

posted @ 2018-03-18 12:10  npe0  阅读(2218)  评论(0编辑  收藏  举报