WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   PL/SQL: Problem mit PK bei insert (http://www.wcm.at/forum/showthread.php?t=217931)

Nestrus 18.06.2007 11:47

PL/SQL: Problem mit PK bei insert
 
Hallo,

ich habe eine tabelle1, bei der die Felder ID und Jahr Primary Key sind.
Jetzt möchte ich "unten dran" noch ein paar Zeilen hängen, die eigentlich kopierte Einträge sind, bei denen sich nur ein Datum ändert.

Ich mach dass so:
insert into tabelle1 (id, jahr, datumvon, ...)
select a.id+10000000, "var_jahr", b.datumvon, ...)
from tabelle1 a left join tabelle2 b on a.id = b.id;

Jetzt bekomme ich imm die Fehlermeldung "unique constraint (%s.%s) violated" bzw. "Verstoß gegen Eindeutigkeit, Regel (xxx.yyy)".

Aber die IDs mit dem summierten Wert sind auf jeden Fall eindeutig, ich habs in eine andere Tabelle getan und keine Zeile mit übereinstimmender ID gefunden. (Die IDs gehen auch nur bis ca 150.000)

Was mache ich falsch??


Danke für eue Hilfe und schöne Grüße
Nestrus

Zeddicus 11.07.2007 07:59

wenns so nicht hinhaut mach doch ein kleines PL/SQL draus.

z.B.:

declare
cursor cur_1 is
select a.id, "var_jahr", b.datumvon, ...)
from tabelle1 a left join tabelle2 b on a.id = b.id;
begin
for rec_1 in cur_1 loop
rec_1.id := rec_1.id + 10000000;
insert into tabelle1 (...) values (rec_1.id, rec_1...);
end loop;
commit;
end;

oder könnte es sein, dass die id zu klein dimensioniert ist und somit die zahlen zu groß sind?

lg zedd


Alle Zeitangaben in WEZ +2. Es ist jetzt 17:14 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag