在mybatis中實現oracle分頁和模糊查詢

2021-08-18 02:28:54 字數 807 閱讀 3651

今天在工作中,遇到乙個業務需求,就是需要在oracle裡進行模糊查詢並分頁,sql語句如下:

select m.label,m.building_loc_id,m.shape.minx x,m.shape.miny y from 

(select rownum rnm ,t.* from table_test  t  where rownum <=10 and t.label like '%茂名%') m

where rnm>5

可以用rownum實現分頁,但是由於rownum是建立在查詢結果上的,所以必須有了查詢結果,才能使用「>」號

所以需要用巢狀語句,而在mybatis中,則需要注意,不能直接用「<」「>」,要用轉義符,也不能直接在引號中使用「#」

select m.label name,m.building_loc_id,m.shape.minx x,m.shape.miny y from 

(select rownum rum,t.* from table_test t where  rownum

<= # and t.label like                     '%

$%' )m

where rum  

>;   #

select count(*) from table_test t where t.label like '%

$%' 

在引號中除了使用「$」,還可以使用concat,但是效率可能會降低,「$」效率較高,但是不安全,可以sql注入

例如:t.lable like concat('%',  concat(#,  '%'))

mybatis批量insert到Oracle資料庫

1 使用mybatis的foreach語法 private static void listinsert system.out.println 60萬條耗時 system.currenttimemillis start 對應的 sql語句 insert into aop trade log id,b...

mybatis使用map批量更新(Oracle)

持久層介面的的方法 void batchupdatelogistics param callmap mapcallmap 對映檔案以下三種寫法均可以,注意 的使用 update td logistics t set t.record where t.sessionid update td logis...

java實現 excel 中資料匯入 oracle

oracle是有乙個叫adi的解決方案 所需的額外包 commons io 1.4 poi bin 3.0.2 思路 使用者選擇要匯入的excel檔案,上傳至web伺服器。然後將檔案存放目錄傳給poi類。通過對row迴圈取到cell的值,最後insert到oracle中。public boolean...