Here are some facts you may want to consider if you use or are planning to use sequences in Oracle.
You cannot use CURRVAL and NEXTVAL in the following constructs:
- A subquery in a
DELETE,SELECT, orUPDATEstatement - A query of a view or of a materialized view
- A
SELECTstatement with theDISTINCToperator - A
SELECTstatement with aGROUPBYclause orORDERBYclause - A
SELECTstatement that is combined with anotherSELECTstatement with theUNION,INTERSECT, orMINUSset operator - The
WHEREclause of aSELECTstatement DEFAULTvalue of a column in aCREATETABLEorALTERTABLEstatement- The condition of a
CHECKconstraint
Also, within a single SQL statement that uses CURRVAL or NEXTVAL, all referenced LONG columns, updated tables, and locked tables must be located on the same database.
When you create a sequence, you can define its initial value and the increment between its values. The first reference to NEXTVAL returns the sequence’s initial value. Subsequent references to NEXTVAL increment the sequence value by the defined increment and return the new value. Any reference to CURRVAL always returns the sequence’s current value, which is the value returned by the last reference to NEXTVAL. Note that before you use CURRVAL for a sequence in your session, you must first initialize the sequence with NEXTVAL.
Possibly related:
- When The Combination of an Oracle Sequence and a PLS_INTEGER is Deadly
- Oracle PL/SQL package initialization
- Oracle Database 11g New PL/SQL Features in your 10g Code Today
Tagged sequence, sql | Post a Comment


















Home > About This Post
This entry was posted by Eddie Awad on Monday, June 13th, 2005, at 9:18 pm, and was filed in Oracle.
Subscribe to the
RSS 2.0 feed for all comments to this post.
Post a Comment