国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

簡單試驗Bulk Binds對性能的提高

2024-07-21 02:39:28
字體:
來源:轉載
供稿:網友

  簡單試驗一下Bulk Binds對性能的提高
  當Oracle運行PL/SQL時會使用兩套引擎,所有PRocedural code由PL/SQL engine 完成,所有SQL由SQL engine處理。 所以假如Oracle從一個collection中循環執行相同的DML操作,那么為了避免兩套engine切換所消耗的系統資源,可以使用bulk binds來把所有的DML操作binding到一次操作中完成。這將極大提高PL/SQL的執行效率。
  以下是簡單的測試,用兩種方式插入100000條數據,可以看到效率提高了7倍左右。
  代碼:--------------------------------------------------------------------------------
  SQL> CREATE TABLE test1(
   2 id NUMBER(10),
   3 description VARCHAR2(50));
  Table created
  SQL> ALTER TABLE test1 ADD (
   2 CONSTRAINT test1_pk PRIMARY KEY (id));
  Table altered
  SQL> SET TIMING ON;
  SQL> DECLARE
   2 TYPE id_type IS TABLE OF test1.id%TYPE;
   3 TYPE description_type IS TABLE OF test1.description%TYPE;
   4
   5 t_id id_type := id_type();
   6 t_description description_type := description_type();
   7 BEGIN
   8 FOR i IN 1 .. 100000 LOOP
   9 t_id.extend;
   10 t_description.extend;
   11
   12 t_id(t_id.last) := i;
   13 t_description(t_description.last) := 'Description: ' To_Char(i);
   14 END LOOP;
   15
   16 FOR i IN t_id.first .. t_id.last LOOP
   17 INSERT INTO test1 (id, description)
   18 VALUES (t_id(i), t_description(i));
   19 END LOOP;
   20
   21 COMMIT;
   22 END;
   23 /
  PL/SQL procedure sUCcessfully completed
  Executed in 141.233 seconds
  SQL> truncate table test1;
  Table truncated
  Executed in 0.631 seconds
  SQL>
  SQL> DECLARE
   2 TYPE id_type IS TABLE OF test1.id%TYPE;
   3 TYPE description_type IS TABLE OF test1.description%TYPE;
   4
   5 t_id id_type := id_type();
   6 t_description description_type := description_type();
   7 BEGIN
   8 FOR i IN 1 .. 100000 LOOP
   9 t_id.extend;
   10 t_description.extend;
   11
   12 t_id(t_id.last) := i;
   13 t_description(t_description.last) := 'Description: ' To_Char(i);
   14 END LOOP;
   15
   16 FORALL i IN t_id.first .. t_id.last
   17 INSERT INTO test1 (id, description)
   18 VALUES (t_id(i), t_description(i));
   19
   20 COMMIT;
   21 END;
   22 /
  PL/SQL procedure successfully completed
  Executed in 27.52 seconds
  SQL> select count(*) from test1;
   COUNT(*)
  ----------
   100000
  Executed in 0.04 seconds
  SQL> right">(出處:清風軟件下載學院)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漳州市| 阿巴嘎旗| 绩溪县| 缙云县| 塘沽区| 泰顺县| 宁强县| 琼中| 洞口县| 康平县| 德化县| 临泽县| 云阳县| 长岛县| 肥城市| 高青县| 赣州市| 朝阳市| 会泽县| 卫辉市| 玉山县| 新和县| 汤阴县| 元阳县| 苏尼特左旗| 浦江县| 梁平县| 汕尾市| 西乡县| 那坡县| 临沧市| 留坝县| 永寿县| 平罗县| 绵竹市| 蚌埠市| 尉犁县| 巴林左旗| 迭部县| 汶川县| 天气|