powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Oracle [игнор отключен] [закрыт для гостей] / forall и save exceptions
8 сообщений из 8, страница 1 из 1
forall и save exceptions
    #39332613
Avotge
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Почитал Handling FORALL Exceptions After FORALL Statement Completes .
Не нашел, есть ли возможность задать заранее, чтобы упал на первом же эксепшене?
То есть у меня есть например 100тыс. id-шников в коллекции
Мне надо пройтись по ним с инсертами/апдейтами, и если на каком-то вдруг упали, то пофиксить его и прервать обработку.
Сейчас все делаю в цикле, но охота переделать на forall, беда в том, что в просто forall нельзя будет пофиксить на каком Id-шнике упали, а save exceptions он будет отрабатывать до конца, хотя мне надо свалиться на первой же ошибке и не тратить время на остальную обработку.
...
Рейтинг: 0 / 0
forall и save exceptions
    #39332639
Фотография -2-
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
AvotgeНе нашел, есть ли возможность задать заранее, чтобы упал на первом же эксепшене?Что тут искать. Не задавай сохранение всех исключений save exceptions.
...
Рейтинг: 0 / 0
forall и save exceptions
    #39332641
Avotge
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
-2-Что тут искать. Не задавай сохранение всех исключений save exceptions.
Тогда без save не подхватить в farall, на каком id свалился.
...
Рейтинг: 0 / 0
forall и save exceptions
    #39332669
Zloxa
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Avotge-2-Что тут искать. Не задавай сохранение всех исключений save exceptions.
Тогда без save не подхватить в farall, на каком id свалился.

Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
SQL> create table test (id number primary key);
Table created

SQL> 
SQL> declare
  2      coll dbms_sql.number_table;
  3  begin
  4      coll(1) := 1;
  5      coll(2) := 1;
  6  
  7      forall i in indices of coll
  8         insert into test values (coll(i));
  9  exception
 10      when others then
 11          dbms_output.put_line('sql%bulk_exceptions.count: '||sql%bulk_exceptions.count);
 12          dbms_output.put_line('sql%bulk_exceptions(1).error_index: '||sql%bulk_exceptions(1).error_index);
 13  end;
 14  /
sql%bulk_exceptions.count: 1
sql%bulk_exceptions(1).error_index: 2
PL/SQL procedure successfully completed
...
Рейтинг: 0 / 0
forall и save exceptions
    #39332675
Фотография -2-
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Avotgeна каком id свалился.id(sql%bulk_rowcount.count+1)?
...
Рейтинг: 0 / 0
forall и save exceptions
    #39332685
Avotge
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Zloxa, интересно, что есть разница между
forall i in coll.first..coll.last
и
forall i in indices of coll
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
declare
      coll dbms_sql.number_table;
begin
       coll(1) := 1;
       coll(2) := 1;
       coll(3) := 1;
       coll(4) := 1;
       coll(5) := 1;       
       forall i in coll.first..coll.last 
          insert into test values (coll(i));
    exception
       when others then
           dbms_output.put_line('sql%bulk_exceptions.count: '||sql%bulk_exceptions.count);
           dbms_output.put_line('sql%bulk_exceptions(1).error_index: '||sql%bulk_exceptions(1).error_index);
end;

sql%bulk_exceptions.count: 1
sql%bulk_exceptions(1).error_index: 2



Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
declare
      coll dbms_sql.number_table;
begin
       coll(1) := 1;
       coll(2) := 1;
       coll(3) := 1;
       coll(4) := 1;
       coll(5) := 1;       
       forall i in indices of coll       
          insert into test values (coll(i));
    exception
       when others then
           dbms_output.put_line('sql%bulk_exceptions.count: '||sql%bulk_exceptions.count);
           dbms_output.put_line('sql%bulk_exceptions(1).error_index: '||sql%bulk_exceptions(1).error_index);
end;

sql%bulk_exceptions.count: 1
sql%bulk_exceptions(1).error_index: 5



Ощущение, что в случае с forall i in indices of coll идет перебор всех id?
-2- , да похоже, что так, только разницу уловить по тексту выше )
...
Рейтинг: 0 / 0
forall и save exceptions
    #39332714
Zloxa
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
AvotgeZloxa, интересно, что есть разница между
forall i in coll.first..coll.last
и
forall i in indices of coll
Походу это как-то связано с insert values. Похоже на то, будто параметры вычисляются предварительно. Не смотря на то, что параметр посчитан, вставка посчитанного значения не производится, двойку в таблицу никто не вставляет.

С insert select все выглядит как-то ожидаемее

Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
Connected to Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 

SQL> 
SQL> /*
  2  create table test (id number primary key);
  3  create function func(param in number) return number
  4  is
  5  begin
  6      dbms_output.put_line(param);
  7      return param;
  8  end;
  9  */
 10  declare
 11      coll dbms_sql.number_table;
 12  begin
 13      coll(1) := 0;
 14      coll(2) := 1;
 15      coll(3) := 1;
 16      coll(4) := 1;
 17      coll(5) := 1;
 18      coll(6) := 2;
 19  
 20      delete from test;
 21      dbms_output.put_line('insert select by indices');
 22      begin
 23          forall i in indices of coll
 24             insert into test select func(coll(i)) from dual;
 25      exception
 26          when others then
 27              dbms_output.put_line('sql%bulk_exceptions.count: '||sql%bulk_exceptions.count);
 28              dbms_output.put_line('sql%bulk_exceptions(1).error_index: '||sql%bulk_exceptions(1).error_index);
 29      end;
 30  
 31      delete from test;
 32      dbms_output.put_line(null);
 33      dbms_output.put_line('insert select by first..last');
 34      begin
 35          forall i in coll.first..coll.last
 36             insert into test select func(coll(i)) from dual;
 37      exception
 38          when others then
 39              dbms_output.put_line('sql%bulk_exceptions.count: '||sql%bulk_exceptions.count);
 40              dbms_output.put_line('sql%bulk_exceptions(1).error_index: '||sql%bulk_exceptions(1).error_index);
 41      end;
 42  
 43      delete from test;
 44      dbms_output.put_line(null);
 45      dbms_output.put_line('insert values by indices');
 46      begin
 47          forall i in indices of coll
 48             insert into test values (func(coll(i)));
 49      exception
 50          when others then
 51              dbms_output.put_line('sql%bulk_exceptions.count: '||sql%bulk_exceptions.count);
 52              dbms_output.put_line('sql%bulk_exceptions(1).error_index: '||sql%bulk_exceptions(1).error_index);
 53      end;
 54  
 55      delete from test;
 56      dbms_output.put_line(null);
 57      dbms_output.put_line('insert values by first..last');
 58      begin
 59          forall i in coll.first..coll.last
 60             insert into test values (func(coll(i)));
 61      exception
 62          when others then
 63              dbms_output.put_line('sql%bulk_exceptions.count: '||sql%bulk_exceptions.count);
 64              dbms_output.put_line('sql%bulk_exceptions(1).error_index: '||sql%bulk_exceptions(1).error_index);
 65      end;
 66  end;
 67  /
insert select by indices
0
1
1
sql%bulk_exceptions.count: 1
sql%bulk_exceptions(1).error_index: 3

insert select by first..last
0
1
1
sql%bulk_exceptions.count: 1
sql%bulk_exceptions(1).error_index: 3

insert values by indices
0
1
1
1
1
2
sql%bulk_exceptions.count: 1
sql%bulk_exceptions(1).error_index: 6

insert values by first..last
0
1
1
1
1
2
sql%bulk_exceptions.count: 1
sql%bulk_exceptions(1).error_index: 3
PL/SQL procedure successfully completed


...
Рейтинг: 0 / 0
forall и save exceptions
    #39333055
Фотография Elic
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
ZloxaПоходу это как-то связано с insert values.forall insert values оптимизирован как одно исполнение с bind-array. Как следствие statement-trigger-а срабатывают один раз, а before-row не мутирует только для первой строки.
...
Рейтинг: 0 / 0
8 сообщений из 8, страница 1 из 1
Форумы / Oracle [игнор отключен] [закрыт для гостей] / forall и save exceptions
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]