简体   繁体   中英

Oracle query in Java Spring MVC does not work properly

<select id="BBSManageDAO.selectBbsSchdulManageList" parameterClass="BoardVO" resultMap="schdulProgramList">
<![CDATA[
SELECT NTT_ID, BBS_ID, NTT_NO, NTT_SJ, SUBSTR(NTT_CN,1,100) NTT_CN, CATEGORY, FRST_REGIST_PNTTM, NTCE_BGNDE, NTCE_ENDDE
,FIELD1, EVN_END_DATE, FIELD2, TELL_NO, USE_AT
FROM TN_BBS A
WHERE 1=1
AND A.USE_AT = 'Y'
AND (
BBS_ID = 'education01_main' or BBS_ID = 'course01_main' or
BBS_ID = 'feestival01_main' or BBS_ID = 'reading01_main'
    )
 ]]>
<isNotEmpty property="searchCondition2">
<isEqual property="searchCondition2" compareValue="DAILY" prepend="AND">
<![CDATA[ #searchSdate# >= FIELD1 AND #searchSdate# <= EVN_END_DATE ]]>
</isEqual>
isEqual property="searchCondition2" compareValue="WEEK" prepend="AND">
<![CDATA[ (#searchBgnDe# <= FIELD1 AND #searchEndDe# >= FIELD1) OR (#searchBgnDe# <= EVN_END_DATE AND #searchEndDe# >= EVN_END_DATE) OR (#searchBgnDe# >= FIELD1 AND #searchEndDe# <= EVN_END_DATE) AND USE_AT='Y']]>
</isEqual>
</isNotEmpty>
<![CDATA[   
 ORDER BY FIELD1 ASC
]]>
</select>

This is the part of the code inside of my SQL_Oracle.xml

This query is about selecting some articles of event if the article fulfill the condition(condition is about date).

I have two APIs. One is daily and the other one is weekly.

In daily query user send a specific date( #searchSdate# ) as a parameter and DB search event which is going on that day.

In weekly user send a week so they give to the server the start date of the week and end date of the week and send back events going on that week.

The problem is though I wrote

WHERE 1=1  
AND A.USE_AT = 'Y'  

When I use the WEEK search they send me the events with 'N' USE_AT data.
I don't care if DAILY send me the same data. But they don't
Finally when I added AND USE_AT='Y ' to end of the WEEK search they worked.

But still I don't know why maybe there is some error of my ibatis grammer.

Does anyone know what's the problem?

There could be an issue with your query above. Try modifying the query with or to brakets around all included in OR comparison: like below

( (#searchBgnDe# <= FIELD1 AND #searchEndDe# >= FIELD1) 
 OR (#searchBgnDe# <= EVN_END_DATE AND #searchEndDe# >= EVN_END_DATE) 
 OR (#searchBgnDe# >= FIELD1 AND #searchEndDe# <= EVN_END_DATE) )
 AND USE_AT='Y'

Also your SQL_Oracle.xml file has xml issue as the second isEqual is not tagged properly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM