oracle char 類型自動填充

今天 在將mysql數據遷移到oracle數據中後,使用springboot、mybaits、oracle 查詢帶有條件的數據。

具體mybatis如下

   <select id="selectCompanyTypicalCaseList" parameterType="com.system.domain.CompanyTypicalCase" resultMap="CompanyTypicalCaseResult">
        <include refid="selectCompanyTypicalCaseVo"/>
        <where>  
            <if test="caseId != null "> and case_id = #{caseId}</if>
             <if test="caseTitle != null  and caseTitle != '' "> and case_title like '%${caseTitle}%'</if>
             <if test="caseType != null  and caseType != '' "> and case_type = #{caseType}</if>
             <if test="picName != null  and picName != '' "> and pic_name = #{picName}</if>
             <if test="picAddress != null  and picAddress != '' "> and pic_address = #{picAddress}</if>
             <if test="linkAddress != null  and linkAddress != '' "> and link_address = #{linkAddress}</if>
             <if test="caseContent != null  and caseContent != '' "> and case_content = #{caseContent}</if>
             <if test="status != null  and status != '' "> and status = #{status}</if>
             <if test="pageView != null "> and page_view = #{pageView}</if>
             <if test="createBy != null  and createBy != '' "> and create_by = #{createBy}</if>
             <if test="createTime != null "> and create_time = #{createTime}</if>
             <if test="updateBy != null  and updateBy != '' "> and update_by = #{updateBy}</if>
             <if test="updateTime != null "> and update_time = #{updateTime}</if>
             <if test="remark != null  and remark != '' "> and remark = #{remark}</if>
         </where>
    </select>
    

但是,不知道爲什麼 當status 爲 Y 時,程序總查不出數據,但是 debug查出的sql 複製出來總能夠查出數據。

一開始考慮mybaits xml寫法的問題,但是幾經修改,沒有試驗成功。

後來靈機一動,感覺是orcale數據問題,幾經查找 發現 由於在oracle中,char類型字段,如果內容長度不夠,會自動以空格方式補足長度。如字段 name char(5),若值爲sgl,那麼oracle會自動用空格補足長度,最終值爲sgl  。

原來,由於在orcle中status屬性設置的長度過長導致。將其屬性長度置爲1即可;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章