From 9297a0dade7749ae8746c618d4993bb0781a95da Mon Sep 17 00:00:00 2001 From: Valeriu PLESNILA Date: Sat, 2 May 2026 10:01:58 +0200 Subject: [PATCH] 2026-05-02 08:01:58 --- bulk_operations/backup_RANDOM_DATA_LOAD.sh | 2 + .../bulk_operations.md | 47 +++++++++++++++++++ bulk_operations/restore_RANDOM_DATA_LOAD.sh | 2 + bulk_operations/run1.sql | 28 +++++++++++ bulk_operations/run2.sql | 14 ++++++ bulk_operations/run3.sql | 14 ++++++ bulk_operations/run4.sql | 28 +++++++++++ 7 files changed, 135 insertions(+) create mode 100755 bulk_operations/backup_RANDOM_DATA_LOAD.sh rename {divers => bulk_operations}/bulk_operations.md (76%) create mode 100755 bulk_operations/restore_RANDOM_DATA_LOAD.sh create mode 100755 bulk_operations/run1.sql create mode 100755 bulk_operations/run2.sql create mode 100755 bulk_operations/run3.sql create mode 100755 bulk_operations/run4.sql diff --git a/bulk_operations/backup_RANDOM_DATA_LOAD.sh b/bulk_operations/backup_RANDOM_DATA_LOAD.sh new file mode 100755 index 0000000..315dbdb --- /dev/null +++ b/bulk_operations/backup_RANDOM_DATA_LOAD.sh @@ -0,0 +1,2 @@ +expdp userid="'/ as sysdba'" dumpfile=MY:RANDOM_DATA_LOAD.dmp logfile=MY:exp_RANDOM_DATA_LOAD.log tables=SAMPLE.RANDOM_DATA_LOAD consistent=Y + diff --git a/divers/bulk_operations.md b/bulk_operations/bulk_operations.md similarity index 76% rename from divers/bulk_operations.md rename to bulk_operations/bulk_operations.md index 309921a..a255859 100644 --- a/divers/bulk_operations.md +++ b/bulk_operations/bulk_operations.md @@ -153,3 +153,50 @@ Instance Id time value cost #Ex #EOF gets NABOOPRD 5 01/05 16:18 1336456799 18858 1 1 12562664 12562664 0 25260 91 51 0 0 197 4089976 ``` + +```sql +var my_action VARCHAR2(30); +exec :my_action:='bulk insert'; + +@login +select sysdate from dual; + +exec DBMS_APPLICATION_INFO.SET_ACTION (action_name => :my_action); +DECLARE + -- Configuration + v_start_val INTEGER := 20000000; + v_count INTEGER := 10000000; + + -- Define the collection type + TYPE t_int_tab IS TABLE OF INTEGER INDEX BY PLS_INTEGER; + v_numbers t_int_tab; +BEGIN + -- 1. Manual Loop to populate the variable + -- This replaces the "BULK COLLECT" step with procedural logic + FOR i IN 1 .. v_count LOOP + v_numbers(i) := v_start_val + (i - 1); + END LOOP; + FORALL i IN 1..v_numbers.COUNT INSERT INTO SAMPLE.RANDOM_DATA_LOAD VALUES(v_numbers(i),'bulk insert',sysdate); + commit; +END; +/ + +select sysdate from dual; +``` + +``` +SQL_TEXT +------------------------------------------------------------------------- +INSERT INTO SAMPLE.RANDOM_DATA_LOAD VALUES(:B1 ,'bulk insert',SYSDATE) + + Elapsed CPU IO + End Plan Buffer time time time + Snap snaphot hash 0ptimizer Buffer gets SQL Disk /exec /exec /exec Elig Inter +Instance Id time value cost #Ex #EOF gets /exec Prof Px reads (sec) (sec) (sec) Mb Mb #Rows +-------- -------- ----------- ---------- ---------- -------- -------- ---------- ----------- ---- ------ ---------- ------- ----- ------ ------- ------- ---------- +NABOOPRD 21 02/05 09:53 0 1 1 1 918750 918750 0 2 72 15 0 0 0 10000000 +``` + + + + diff --git a/bulk_operations/restore_RANDOM_DATA_LOAD.sh b/bulk_operations/restore_RANDOM_DATA_LOAD.sh new file mode 100755 index 0000000..dfecd02 --- /dev/null +++ b/bulk_operations/restore_RANDOM_DATA_LOAD.sh @@ -0,0 +1,2 @@ +impdp userid="'/ as sysdba'" dumpfile=MY:RANDOM_DATA_LOAD.dmp logfile=MY:imp_RANDOM_DATA_LOAD.log tables=SAMPLE.RANDOM_DATA_LOAD TABLE_EXISTS_ACTION=replace + diff --git a/bulk_operations/run1.sql b/bulk_operations/run1.sql new file mode 100755 index 0000000..a7665b4 --- /dev/null +++ b/bulk_operations/run1.sql @@ -0,0 +1,28 @@ +var my_action VARCHAR2(30); +exec :my_action:='bulk delete'; + +@login +select sysdate from dual; + +exec DBMS_APPLICATION_INFO.SET_ACTION (action_name => :my_action); + +DECLARE + TYPE id_col_table_type IS TABLE OF SAMPLE.RANDOM_DATA_LOAD.id_col%TYPE; + id_col_table id_col_table_type; + +BEGIN + -- Retrieve data to be deleted in bulk + SELECT id_col BULK COLLECT INTO id_col_table FROM SAMPLE.RANDOM_DATA_LOAD WHERE date_col <= date'2022-06-15'; + + -- Perform bulk delete + FORALL i IN 1..id_col_table.COUNT + DELETE FROM SAMPLE.RANDOM_DATA_LOAD WHERE id_col = id_col_table(i); + + COMMIT; +END; +/ + +select sysdate from dual; + +exec DBMS_APPLICATION_INFO.SET_ACTION (action_name => NULL); + diff --git a/bulk_operations/run2.sql b/bulk_operations/run2.sql new file mode 100755 index 0000000..cc542be --- /dev/null +++ b/bulk_operations/run2.sql @@ -0,0 +1,14 @@ +var my_action VARCHAR2(30); +exec :my_action:='classic delete 1'; + +@login +select sysdate from dual; + +exec DBMS_APPLICATION_INFO.SET_ACTION (action_name => :my_action); + +delete from SAMPLE.RANDOM_DATA_LOAD where id_col in (select id_col from SAMPLE.RANDOM_DATA_LOAD WHERE date_col <= date'2022-06-15'); + +select sysdate from dual; + +exec DBMS_APPLICATION_INFO.SET_ACTION (action_name => NULL); + diff --git a/bulk_operations/run3.sql b/bulk_operations/run3.sql new file mode 100755 index 0000000..822c698 --- /dev/null +++ b/bulk_operations/run3.sql @@ -0,0 +1,14 @@ +var my_action VARCHAR2(30); +exec :my_action:='classic delete 2'; + +@login +select sysdate from dual; + +exec DBMS_APPLICATION_INFO.SET_ACTION (action_name => :my_action); + +delete from SAMPLE.RANDOM_DATA_LOAD where date_col <= date'2022-06-15'; + +select sysdate from dual; + +exec DBMS_APPLICATION_INFO.SET_ACTION (action_name => NULL); + diff --git a/bulk_operations/run4.sql b/bulk_operations/run4.sql new file mode 100755 index 0000000..849c6ce --- /dev/null +++ b/bulk_operations/run4.sql @@ -0,0 +1,28 @@ +var my_action VARCHAR2(30); +exec :my_action:='bulk insert'; + +@login +select sysdate from dual; + +exec DBMS_APPLICATION_INFO.SET_ACTION (action_name => :my_action); +DECLARE + -- Configuration + v_start_val INTEGER := 20000000; + v_count INTEGER := 10000000; + + -- Define the collection type + TYPE t_int_tab IS TABLE OF INTEGER INDEX BY PLS_INTEGER; + v_numbers t_int_tab; +BEGIN + -- 1. Manual Loop to populate the variable + -- This replaces the "BULK COLLECT" step with procedural logic + FOR i IN 1 .. v_count LOOP + v_numbers(i) := v_start_val + (i - 1); + END LOOP; + FORALL i IN 1..v_numbers.COUNT INSERT INTO SAMPLE.RANDOM_DATA_LOAD VALUES(v_numbers(i),'bulk insert',sysdate); + commit; +END; +/ + +select sysdate from dual; +