PDA

View Full Version : Stored Procedure SQL Cursor Update



Jenne
14-06-05, 11:59
Hallo Kollegen,
leider habe ich ein Problem und komme einfach nicht weiter.

Ich möchte mit Stored Procdure ein Feld in einer Tabelle ändern. Der Änderungsinhalt kommt aus einer anderen Tabellen bei der es keine Eindeutigkeit gibt. Also habe ich folgendes geschrieben.

DECLARE C1 DYNAMIC SCROLL CURSOR WITH HOLD FOR SELECT ifa_art.darreich_form
from jenne/artikel,Jenne/ifa_art
WHERE artikel.zentral_nr = ifa_art.zentral_nr and
current timestamp between artikel.gueltig_von and gueltig_bis and
artikel.darreich_form = ' ' and ifa_art.darreich_form <> '---'
ORDER BY ifa_art.gueltigkeit desc for update of artikel.darreich_form

Open C1
repeat
fetch first from c1
if sqlcod = 100 then
end repeat
else
Update jenne/artikel set Darreich_form = ifa_art.darreich_form
where current of c1
end if
close c1

Aber leider bekomme ich eine Mitteilung das Update nicht erlaubt ist.
Wo liegt mein Fehler ?
Vielleicht könnt Ihr mir Helfen.
Danke im Voraus
Jenne

Fuerchau
14-06-05, 12:18
Leider ist ein Join-Cursor (from file1, file2) NICHT änderbar !
Du musst entweder deine Logik umbauen oder einen gezielten "Update ... set " codieren.

Jenne
14-06-05, 14:00
Hallo Fuerchau,

jetzt habe ich meine Logik umgebaut aber nur wird mir mitgeteilt das Schlüsselwort 'OPEN' wird nicht erwartet. Ich glaube ich habe mich völlig verrannt.

DECLARE C1 DYNAMIC SCROLL CURSOR WITH HOLD FOR SELECT artikel.artikel_nr,
ifa_art.darreich_form
from jenne/artikel,Jenne/ifa_art
WHERE artikel.zentral_nr = ifa_art.zentral_nr and
current timestamp between artikel.gueltig_von and gueltig_bis and
artikel.darreich_form = ' ' and ifa_art.darreich_form <> '---'
ORDER BY ifa_art.gueltigkeit desc

open C1
repeat
fetch first from c1 into :artikelnr,:darform
if sqlcod = 100 then
end repeat
else
update jenne/artikel set Darreich_form = darform
where artikel_nr = :artnr
end if
close c1

Gruß
Jenne