"Insert /*+Append */ Values", épisode 3 : PL/SQL

Vous pouvez aussi remplacer l’étape 2 du post précédent par un code en PL/SQL comme celui qui suit:

connect / as sysdba

grant select on sys.v_$mystat
to demo

connect demo/demo

set serveroutput on
declare
id dbms_utility.number_array;
text dbms_utility.lname_array;
dpw number;
begin
-- Get Direct Path Write Statistic
select value into dpw
from v$mystat
where statistic# = 73;
-- Fill Arrays of Variables
for i in 1..10000 loop
id(i):=i;
text(i):=to_char(i);
end loop;
-- Insert the Arrays With Direct
-- Path Write, The Append Hint
-- and the Values clause
forall i in 1..10000
insert /*+ append */
into insertappend(id,text)
values (id(i),text(i));
-- Get the Session Direct Path Write
-- Statistic in
select value-dpw
into dpw
from v$mystat
where statistic# = 73;
dbms_output.put_line('Direct Path Write: '||
to_char(dpw));
end;
/
rollback;

Direct Path Write: 20

A noter que la clause SAVE EXCEPTIONS ne fonctionne pas dans ce cas:

set serveroutput on
declare
id dbms_utility.number_array;
text dbms_utility.lname_array;
dpw number;
begin
-- Get Direct Path Write Statistic
select value into dpw
from v$mystat
where statistic# = 73;
-- Fill Arrays of Variables
for i in 1..10000 loop
id(i):=i;
text(i):=to_char(i);
end loop;
-- Insert the Arrays With Direct
-- Path Write, The Append Hint
-- and the Values clause
forall i in 1..10000
save exceptions
insert /*+ append */
into insertappend(id,text)
values (id(i),text(i));
-- Get the Session Direct Path Write
-- Statistic in
select value-dpw
into dpw
from v$mystat
where statistic# = 73;
dbms_output.put_line('Direct Path Write: '||
to_char(dpw));
end;
/
ERROR at line 1:
ORA-38910: BATCH ERROR mode is not supported for this operation
ORA-06512: at line 18

Merci Ghassan pour la syntaxe!