Pl/sql frage

hallo zusammen
ich habe einen lkeinen problem mit collection beim delete:
TYPE parent_child_typ IS RECORD(
parent_id INTEGER := 0,
child_id INTEGER := 0);

parent_child parent_child_typ;
TYPE master_table_type IS TABLE OF parent_child_typ;
master_table master_table_type := master_table_type();

bein einfügen ist kein priblem:
master_table.extend;–null am ende einfügen

master_table(master_table.last).parent_id := info;
master_table(master_table.last).child_id := info;

beim löschen taucht das problem erst beim 2 durchlauf!!
value eroor:ora-06502
die ursachen:
a subscript is null or not convertible to the key type. This exception might occur if the key is defined as a PLS_INTEGER range, and the subscript is outside this range

FOR i IN master_table.FIRST … master_table.LAST
LOOP
if i = null then
null;
else

IF master_table(i).child_id = form_id.id THEN
master_table.delete(i);
END IF;
end if;

END LOOP;

wie soll ich mein schleife ändern damit ich diese fehler vermeide

Hi,

if i = null then

Dieser Vergleich schlägt immer fehl. Du mußt auf Null testen:

if i IS NULL then

Gruß

J.

ich habe das korigiert aber ich bekomme die fehler immer noch?

FOR i IN master_table.FIRST … master_table.LAST
LOOP
if i is not null then
IF master_table(i).child_id = form_id.id THEN
master_table.delete(i);
END IF;
end if;

END LOOP;

kannst du mir weiter helfen

Hi,

ich habe das korigiert aber ich bekomme die fehler immer noch?

Welche Fehler bekommst Du denn genau?

Ich weiß nicht, ob ich genau kapiert habe, was Du machen willst. Ich habe folgenden Code im SQLPlus eingegeben:

(Übrigens: benutze den Pre-Tag, um Code formatiert zu posten)

SQL\> set serveroutput on
SQL\> declare
 2 TYPE parent\_child\_typ IS RECORD(
 3 parent\_id INTEGER := 0,
 4 child\_id INTEGER := 0);
 5
 6 parent\_child parent\_child\_typ;
 7 TYPE master\_table\_type IS TABLE OF parent\_child\_typ;
 8 master\_table master\_table\_type := master\_table\_type();
 9
 10 ---bein einfügen ist kein priblem:
 11 begin
 12 master\_table.extend;--null am ende einfügen
 13 master\_table(master\_table.last).parent\_id := 15;
 14 master\_table(master\_table.last).child\_id := 15;
 15
 16 master\_table.extend;--null am ende einfügen
 17 master\_table(master\_table.last).parent\_id := 10;
 18 master\_table(master\_table.last).child\_id := 20;
 19
 20 -- Das geht!
 21 master\_table(1).parent\_id := 35;
 22 master\_table(2).child\_id := 45;
 23 -- Das würde einen Fehler produzieren
 24 -- master\_table(3).child\_id := 35;
 25
 26 FOR i IN master\_table.FIRST .. master\_table.LAST
 27 LOOP
 28 dbms\_output.put\_line(i);
 29 -- die 45 soll Deine form\_id.id simulieren
 30 IF master\_table(i).child\_id = 45 THEN
 31 dbms\_output.put\_line('Deleted: ' || i || ', id: ' || master\_table(i).child\_id);
 32 master\_table.delete(i);
 33 END IF;
 34 END LOOP;
 35 end;
 36 /
1
2
Deleted: 2, id: 45

PL/SQL procedure successfully completed.

SQL\>
SQL\> set serveroutput on
SQL\> declare
 2 TYPE parent\_child\_typ IS RECORD(
 3 parent\_id INTEGER := 0,
 4 child\_id INTEGER := 0);
 5
 6 parent\_child parent\_child\_typ;
 7 TYPE master\_table\_type IS TABLE OF parent\_child\_typ;
 8 master\_table master\_table\_type := master\_table\_type();
 9
 10 ---bein einfügen ist kein priblem:
 11 begin
 12 master\_table.extend;--null am ende einfügen
 13 master\_table(master\_table.last).parent\_id := 15;
 14 master\_table(master\_table.last).child\_id := 15;
 15
 16 master\_table.extend;--null am ende einfügen
 17 master\_table(master\_table.last).parent\_id := 10;
 18 master\_table(master\_table.last).child\_id := 20;
 19
 20 -- Das geht!
 21 master\_table(1).parent\_id := 35;
 22 master\_table(2).child\_id := 45;
 23 -- Das würde einen Fehler produzieren
 24 master\_table(3).child\_id := 35;
 25
 26 FOR i IN master\_table.FIRST .. master\_table.LAST
 27 LOOP
 28 dbms\_output.put\_line(i);
 29 -- die 45 soll Deine form\_id.id simulieren
 30 IF master\_table(i).child\_id = 45 THEN
 31 dbms\_output.put\_line('Deleted: ' || i || ', id: ' || master\_table(i).child\_id);
 32 master\_table.delete(i);
 33 END IF;
 34 END LOOP;
 35 end;
 36 /
declare
\*
ERROR at line 1:
ORA-06533: Subscript beyond count
ORA-06512: at line 35
ORA-06512: at line 24

So, jetzt bist Du dran: bitte poste Deinen Code komplett und die auftretenden Fehlermeldungen genauso, dann können wir das nachvollziehen.

Gruß

J.

1 Like

Hallo Youssef!

Der NOT NULL Vergleich ist jetzt schon mal richtig. Zu Deinem anderen Problem habe ich in der Oracle Doku folgendes gefunden:

When it includes deleted elements, the internal size of a nested table differs from the values returned by COUNT and LAST. For instance, if you initialize a nested table with five elements, then delete elements 2 and 5, the internal size is 5, COUNT returns 3, and LAST returns 4. All deleted elements (whether leading, in the middle, or trailing) are treated alike

Im obigen Fall würde also Deine FOR-Schleife im zweiten Durchlauf den Index 2 Verwenden, obwohl das Element dort schon gelöscht wurde. Deshalb auch der Fehler (vermute ich mal). Ich hab es nicht probiert, aber versuch doch mal mit PRIOR() bzw. NEXT() zu arbeiten, das müßte eigentlich gelöschte Elemente übersprigen…

Gruß,
TheBeast

Hallo, du hast recht
ich habe das problem so gelöst:

i := master_table.FIRST; – get subscript of first element
WHILE i IS NOT NULL
LOOP
if master_table(i).child_id = form_id.id then
master_table.delete(i);
end if;
i := master_table.NEXT(i); – get subscript of next element
END LOOP;

ich möchte dass mein array von alle masken in der anwendung(eine runtime module) benutzt wird(irgendwie global).
und für jede andere runtime module soll ein andere array existieren
hast du eine idee wie kann man es realisieren
danke im voraus

youssef

Hi Youssef!

ich möchte dass mein array von alle masken in der
anwendung(eine runtime module) benutzt wird(irgendwie global).
und für jede andere runtime module soll ein andere array
existieren

Äääääähmmm… Bahnhof. Beschreib mir bitte mal (wenn Du willst auch per mail) genauer, was denn das Programm so tun soll, wofür die Arrays gedacht sind und vor allem um was für eine Anwendung es sich hier handeln soll (Web, Server-Client, Standalone, whatever…).

Gruß,
TheBeast