Mybatis注解方式操作Oracle數(shù)據(jù)庫(kù)詳解
1.新增多行數(shù)據(jù)
@Insert({"<script>insert all " +
"<foreach collection=\"list\" index=\"index\" item=\"item\" open=\"\" separator=\"\" close=\"\">" +
" into s_user (user,username) values " +
"(#{item.user},#{item.username}) " +
"</foreach>" +
" select 1 from dual " +
"</script>"})
2.執(zhí)行多條SQL語(yǔ)句
特別注意:open屬性設(shè)置為begin,close設(shè)置為;end;
@Update({"<script>" +
"<foreach collection=\"list\" separator=\";\" item=\"item\" open=\"begin\" close=\";end;\">" +
"update s_user set user=#{item.user},username=#{item.username} where id=#{item.id}" +
"</foreach>" +
"</script>"})
ORACLE中通過(guò)begin...end;來(lái)執(zhí)行多行sql語(yǔ)句,各條sql之間用;分割
補(bǔ)充知識(shí):使用mybatis注解批量插入Oracle數(shù)據(jù)庫(kù)與批量插入MySQL數(shù)據(jù)庫(kù)區(qū)別
批量插入MySQL語(yǔ)法
insert into table_name values (column01, column02, ...), (value01, value02, ...),
(value01, value02, ...);
例子:
@Select({"<script>" ,
"insert into t_sales_target (area_id, area_name, shop_id, shop_name, year) values " ,
" <foreach collection='saleTargetList' item='item' index='index' separator=','>",
" (",
" #{item.areaId},",
" #{item.areaName},",
" #{item.shopId},",
" #{item.shopName},",
" #{item.year},"
" )",
" </foreach>",
"</script>"
} )
批量插入Oracle語(yǔ)法
insert into table_name (column01, column02, ...) select * from ( select value01, value02, ... from dual union select value01, value02, ... from dual union select value01, value02, ... from dual )
例子:
@Insert({"<script>",
"insert into t_sales_date_amount (amount, sale_date, shop_id, area_id) select A.* from (",
" <foreach collection='salesDateAmountList' item='item' index='index' separator='UNION ALL'>",
" SELECT",
" #{item.salesAmount},",
" #{item.salesDateTime},",
" #{item.shopId},",
" #{item.areaId}",
" from dual",
" </foreach>",
" )A",
"</script>"
})
以上這篇Mybatis注解方式操作Oracle數(shù)據(jù)庫(kù)詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解析Java編程中設(shè)計(jì)模式的開(kāi)閉原則的運(yùn)用
這篇文章主要介紹了解析Java編程中設(shè)計(jì)模式的開(kāi)閉原則的運(yùn)用,開(kāi)閉原則多應(yīng)用于Java程序的擴(kuò)展開(kāi)發(fā)方面,需要的朋友可以參考下2016-02-02
使用spring框架實(shí)現(xiàn)數(shù)據(jù)庫(kù)事務(wù)處理方式
這篇文章主要介紹了使用spring框架實(shí)現(xiàn)數(shù)據(jù)庫(kù)事務(wù)處理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10
Java超詳細(xì)講解接口的實(shí)現(xiàn)與用法
Java接口是一系列方法的聲明,是一些方法特征的集合,一個(gè)接口只有方法的特征沒(méi)有方法的實(shí)現(xiàn),因此這些方法可以在不同的地方被不同的類實(shí)現(xiàn),而這些實(shí)現(xiàn)可以具有不同的行為2022-04-04
SpringBoot?MongoCustomConversions自定義轉(zhuǎn)換方式
這篇文章主要介紹了SpringBoot?MongoCustomConversions自定義轉(zhuǎn)換方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08
Java視頻斷點(diǎn)上傳的實(shí)現(xiàn)示例
斷點(diǎn)續(xù)傳指的是在下載或上傳時(shí),將下載或上傳任務(wù)人為的劃分為幾個(gè)部分,本文主要介紹了Java視頻斷點(diǎn)上傳的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-05-05
Java concurrency線程池之Callable和Future_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要為大家詳細(xì)介紹了Java concurrency線程池之Callable和Future,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
Curator實(shí)現(xiàn)zookeeper的節(jié)點(diǎn)監(jiān)聽(tīng)詳解
這篇文章主要介紹了Curator實(shí)現(xiàn)zookeeper的節(jié)點(diǎn)監(jiān)聽(tīng)詳解,Curtor框架中一共有三個(gè)實(shí)現(xiàn)監(jiān)聽(tīng)的方式,一種是NodeCache監(jiān)聽(tīng)指定節(jié)點(diǎn),一種是pathChildrenCache監(jiān)聽(tīng)子節(jié)點(diǎn),一種是TreeCache可以監(jiān)控所有節(jié)點(diǎn) 相當(dāng)于以上兩種的合集,需要的朋友可以參考下2023-12-12

