ORACLE批量操作
ORACLE批量操作
---------------------------------------------------------------------------
-- 建立表
----------------------------------------------------------------------------
drop table demo;
create table demo (id number, name varchar2(255));
----------------------------------------------------------------------------
-- 批量操作
----------------------------------------------------------------------------
declare
type id_table_type is table of number index by binary_integer;
type name_table_type is table of varchar2(255) index by binary_integer;
id_table id_table_type;
name_table name_table_type;
start_time number;
end_time number;
v_count number := 100000;
begin
--------------------------------------------------------------------------
-- 1、不使用批量插入資料
--------------------------------------------------------------------------
for i in 1 .. v_count loop
id_table(i) := i;
name_table(i) := 'name' || i;
end loop;
start_time := dbms_utility.get_time;
for i in 1 .. v_count loop
insert /*+append*/
into demo
values
(id_table(i), name_table(i));
end loop;
end_time := dbms_utility.get_time;
dbms_output.put_line('不用批量插入' || v_count || '條:' ||
lpad(to_char((end_time - start_time) / 100), 5, ' '));
--------------------------------------------------------------------------
-- 2、使用批量插入資料
--------------------------------------------------------------------------
for i in v_count + 1 .. v_count * 2 loop
id_table(i) := i;
name_table(i) := 'name' || i;
end loop;
start_time := dbms_utility.get_time;
forall i in v_count + 1 .. v_count * 2
insert /*+append*/
into demo
values
(id_table(i), name_table(i));
end_time := dbms_utility.get_time;
dbms_output.put_line(' 用批量插入' || v_count || '條:' ||
lpad(to_char((end_time - start_time) / 100), 5, ' '));
--------------------------------------------------------------------------
-- 3、使用批量更新資料
--------------------------------------------------------------------------
for i in 1 .. v_count loop
id_table(i) := i;
name_table(i) := 'NB' || i;
end loop;
start_time := dbms_utility.get_time;
for i in 1 .. v_count loop
update demo set name = name_table(i) where id = id_table(i);
end loop;
end_time := dbms_utility.get_time;
dbms_output.put_line('不用批量更新' || v_count || '條:' ||
lpad(to_char((end_time - start_time) / 100), 5, ' '));
start_time := dbms_utility.get_time;
forall i in v_count + 1 .. v_count * 2
update demo set name = name_table(i) where id = id_table(i);
end_time := dbms_utility.get_time;
dbms_output.put_line(' 用批量更新' || v_count || '條:' ||
lpad(to_char((end_time - start_time) / 100), 5, ' '));
--------------------------------------------------------------------------
-- 4、使用批量刪除資料
--------------------------------------------------------------------------
for i in 1 .. v_count loop
id_table(i) := i;
end loop;
start_time := dbms_utility.get_time;
forall i in 1 .. id_table.count
delete from demo where id = id_table(i);
end_time := dbms_utility.get_time;
dbms_output.put_line(' 用批量刪除' || v_count || '條:' ||
lpad(to_char((end_time - start_time) / 100), 5, ' '));
end;
/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/720091/viewspace-1057796/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ibatis對oracle資料庫的批量更新和批量插入的操作BATOracle資料庫
- mybatis批量操作MyBatis
- Mybatis批量操作demoMyBatis
- DocumentFragment批量操作domFragment
- 水煮oracle29----oracle中對資料的批量操作測試Oracle
- mongodb批量操作, bulk_write,MongoDB
- 監控批量操作進度
- Oracle批量kill sessionOracleSession
- 深度解析Django REST Framework 批量操作DjangoRESTFramework
- 使用PrepareStatement實現批量插入操作REST
- mybatis 的crud及批量cud操作MyBatis
- CQRS批量操作的效能問題
- oracle批量插入資料Oracle
- Mybatis批量插入Oracle、MySQLMyBatisOracleMySql
- oracle批量刪除表Oracle
- oracle批量重建索引方法Oracle索引
- shell指令碼批量操作使用者指令碼
- php中對MYSQL操作之批量執行,與獲取批量結果PHPMySql
- Oracle 批量建表空間Oracle
- oracle批量新增更新資料Oracle
- oracle下批量增加序列值Oracle
- Redisson批量操作類RBuckets和管道利器RBatchRedisBAT
- Android 基於RecyclerView實現批量操作AndroidView
- Linux下使用Ansible處理批量操作Linux
- 使用PSSH批量操作Linux伺服器Linux伺服器
- 大批量資料處理操作小記
- oracle 批量刪除觸發器Oracle觸發器
- Oracle -- 批量更新sequence的儲存Oracle
- Oracle總結第二篇【檢視、索引、事務、使用者許可權、批量操作】Oracle索引
- ES 筆記四:文件的基本 CRUD 與批量操作筆記
- 通過shell指令碼批量操作mysql資料庫指令碼MySql資料庫
- Docker批量操作(啟停、刪除、歸檔、載入)Docker
- SharePoint REST API - 一個請求批量操作RESTAPI
- Vim常用操作-Nginx配置檔案批量加註釋。Nginx
- 使用PSSH批量SSH操作Linux伺服器Linux伺服器
- 批量解決oracle鎖等待的方法Oracle
- ORACLE表批量遷移表空間Oracle
- Oracle 集合操作Oracle