From the course: Oracle Database 19c: Advanced SQL

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Sequences

Sequences

- [Instructor] Databases need unique numbers in guaranteeing uniqueness mainly for generating primary keys in a table. And there are two ways to do it. Either you can use a sequence or a special identity column data type. First, you need to know what a sequence is. Well, it's a data dictionary object and lives only in the data dictionary. It generates a unique number and is guaranteed to be unique regardless of how many different users access it and how often. Gaps in the sequence are possible but usually not an issue. You also might use one sequence for a different column and many tables or you could have a sequence dedicated to a table. Why do you use sequences? Usually for generating primary keys in one table or even several tables. Or you could use the sequence to provide ordering for multiple tables across schemas. The sequence value is still unique. The way you access a sequence is via the sequence name qualified with either CURRVAL or NEXTVAL. CURRVAL always returns the current…

Contents