0% found this document useful (0 votes)
66 views

Assignment No

This document discusses how to use sequences in Oracle to automatically generate unique primary keys. Sequences are database objects that generate integer sequences independent of transactions. They allow multiple users to concurrently generate unique sequence numbers that may have gaps. After a sequence is created with the CREATE SEQUENCE statement, its values can be accessed using the CURRVAL and NEXTVAL pseudocolumns to return the current or next sequence number.

Uploaded by

Charudatta Yelne
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Assignment No

This document discusses how to use sequences in Oracle to automatically generate unique primary keys. Sequences are database objects that generate integer sequences independent of transactions. They allow multiple users to concurrently generate unique sequence numbers that may have gaps. After a sequence is created with the CREATE SEQUENCE statement, its values can be accessed using the CURRVAL and NEXTVAL pseudocolumns to return the current or next sequence number.

Uploaded by

Charudatta Yelne
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT NO.

1
TO DISPLAY ADVANCED FEATURE OF ORACLE LANGUAGE. SEQUENCE OBJECT In Oracle, you can create an autonumber field by using sequences. A sequence is an object in Oracle that is used to generate a number sequence. This can be useful when you need to create a unique number to act as a primary key. Use the CREATE SEQUENCE statement to create a sequence, which is a database object from which multiple users may generate unique integers. You can use sequences to automatically generate primary key values. When a sequence number is generated, the sequence is incremented, independent of the transaction committing or rolling back. If two users concurrently increment the same sequence, then the sequence numbers each user acquires may have gaps, because sequence numbers are being generated by the other user. One user can never acquire the sequence number generated by another user. After a sequence value is generated by one user, that user can continue to access that value regardless of whether the sequence is incremented by another user. Sequence numbers are generated independently of tables, so the same sequence can be used for one or for multiple tables. It is possible that individual sequence numbers will appear to be skipped, because they were generated and used in a transaction that ultimately rolled back. Additionally, a single user may not realize that other users are drawing from the same sequence.

After a sequence is created, you can access its values in SQL statements with the CURRVAL pseudocolumn, which returns the current value of the sequence, or the NEXTVAL pseudocolumn, which increments the sequence and returns the new value. The syntax for a sequence is: CREATE SEQUENCE sequence_name MINVALUE value MAXVALUE value START WITH value INCREMENT BY value CACHE value; For example: CREATE SEQUENCE supplier_seq MINVALUE 1 MAXVALUE 99999 START WITH 1 INCREMENT BY 1 CACHE 20; This would create a sequence object called supplier_seq. The first sequence number that it would use is 1 and each subsequent number would increment by 1 (ie: 2,3,4,...}. It will cache up to 20 values for performance.

OUTPUT

You might also like