Oracle: NextVal einer Sequence ermitteln

Gray

Erfahrenes Mitglied
Folgendes hab ich versucht:
PHP:
$stmt=OCIParse($db, "SELECT GN_ARTIKEL_S1.nextval FROM DUAL");
OCIExecute($stmt);
OCIFetch($stmt);
$nextid=OCIResult($stmt, "NEXTVAL");
echo $nextid;

das funktioniert auch fast, allerdings wird der Wert der Sequence hierbei hochgezählt, das soll er jedoch nicht, ich will Ihn ja lediglich anzeigen lassen.
 
das wäre dann currval. Allerdings muss eine Sequence in der Session erst über nextval initialisiert werden, ehe man auf currval zugreifen kann.

Oder wie es in der 10.2er Doku heisst:

When you create a sequence, you can define its initial value and the increment between its values. The first reference to NEXTVAL returns the initial value of the sequence. Subsequent references to NEXTVAL increment the sequence value by the defined increment and return the new value. Any reference to CURRVAL always returns the current value of the sequence, which is the value returned by the last reference to NEXTVAL.

Before you use CURRVAL for a sequence in your session, you must first initialize the sequence with NEXTVAL.

Gruß

MP
 
Wenn du einen Stand über deine Sequences haben willst kannst du die View USER_SEQUENCES abfragen. Also:

SQL:
SELECT *
FROM USER_SEQUENCES
WHERE SEQUENCE_NAME = 'GN_ARTIKEL_S1';

Die Zahl ist allerdings nur ein "Richtwert" und sollte in keinem Fall benutzt werden um eine neue ID zu erzeugen. Dafür ist einzig und allein NEXTVAL zuständig.
 
Zuletzt bearbeitet von einem Moderator:

Neue Beiträge

Zurück