background image
<< Dropping a View | Creating Database Sequences >>
<< Dropping a View | Creating Database Sequences >>

Using Sequences

Using Sequences
Creating and Using Database Objects 3-25
You deleted the view. The equivalent SQL statement for dropping the view is:
DROP VIEW sales_marketing;
Using Sequences
Sequences are database objects that generate unique sequential values, which are very
useful when you need unique primary keys. The
hr
schema already has three such
sequences:
departments_seq
,
employees_seq
, and
locations_seq
.
The sequences are used through these pseudocolumns:
The
CURRVAL
pseudocolumn returns the current value of a sequence.
CURRVAL
can only be used after an initial call to
NEXTVAL
initializes the sequence.
The
NEXTVAL
pseudocolumn increments the sequence and returns the next value.
The first time that
NEXTVAL
is used, it returns the initial value of the sequence.
Subsequent references to
NEXTVAL
increment the sequence value by the defined
increment, and return the new value.
Note that a sequence is not connected to any other object, except for conventions of
use. When you plan to use a sequence to populate the primary key of a table, Oracle
recommends that you use a naming convention to link the sequence to that table.
Throughout this discussion, the naming convention for such sequences is table_
name
_seq
.
Creating a Sequence
You can create a sequence in the SQL Developer Interface, or using the SQL Statement
window.
To create a sequence using the SQL Developer interface:
The following steps will create a sequence,
evaluations_seq,
that you can use for
the primary key of the
evaluations
table.
1.
In the Connections navigation hierarchy, right-click Sequences.
2.
Select New Sequence.
See Also:
Oracle Database SQL Language Reference for information on the
CREATE VIEW
statement
Oracle Database SQL Language Reference for information on the
DROP VIEW
statement
See Also:
Oracle Database SQL Language Reference