SlideShare a Scribd company logo
E R Y K B U D I P R A T A M A
T I F L A B A S S I S T A N T – I N F O R M A T I C S E N G I N E E R I N G
ORACLE DATABASE
SEQUENCE
DEFINITION
• Just like tables, views, indexes, and
synonyms, a sequence is a type of database
object.
• Sequences are used to generate unique,
sequential integer values that are used as
primary key values in database tables.
• The sequence of numbers can be
generated in either ascending or
descending order.
SEQUENCE SYNTAX
CREATE SEQUENCE <sequence name>
[INCREMENT BY <number>]
[START WITH <start value number>]
[MAXVALUE <MAXIMUM VLAUE NUMBER>]
[NOMAXVALUE]
[MINVALUE <minimum value number>]
[CYCLE]
[NOCYCLE]
[CACHE <number of sequence value to cache>]
[NOCACHE]
[ORDER]
[NOORDER];
EXAMPLE
CREATE SEQUENCE
order_number_sequence
INCREMENT BY 1
START WITH 1
MAXVALUE 100000000
MINVALUE 1
CYCLE
CACHE 10;
Sequence created.
ACCESSING SEQUENCE VALUES
• Sequence values are generated through the use of
two pseudocolumns named currval and nextval.
• A pseudocolumn behaves like a table column, but
psuedocolumns are not actually stored in a table.
• We can select values from pseudocolumns but
cannot perform manipulations on their values.
• The first time you select the nextval pseudocolumn,
the initial value in the sequence is returned.
• Subsequent selections of the nextval pseudocolumn
will cause the sequence to increment as specified
by the INCREMENT BY clause and will return the
newly generated sequence value.
• The currval pseudocolumn returns the
current value of the sequence, which is the
value returned by the last reference to
nextval.
Example
CREATE TABLE sales_order (
order_number NUMBER(9)
CONSTRAINT pk_sales_order PRIMARY KEY,
order_amount NUMBER(9,2));
• The INSERT commands shown below insert three
rows into the sales_order table. The INSERT
commands reference the
order_number_sequence.nextval pseudocolumn.
INSERT INTO sales_order
VALUES(order_number_sequence.nextval,
155.59 );
INSERT INTO sales_order
VALUES(order_number_sequence.nextval,
450.00 );
INSERT INTO sales_order
VALUES(order_number_sequence.nextval,
16.95);
SELECT * FROM sales_order;
ORDER_NUMBER ORDER_AMOUNT
------------ ------------
1 155.59
2 450
3 16.95
• Use of currval.
CREATE TABLE order_details (
order_number NUMBER(9),
order_row NUMBER(3),
product_desc VARCHAR2(15),
quantity_ordered NUMBER(3),
product_price NUMBER(9,2),
CONSTRAINT pk_order_details
PRIMARY KEY (order_number, order_row),
CONSTRAINT fk_order_number FOREIGN KEY
(order_number) REFERENCES sales_order);
• The order_details table has a FOREIGN
KEY reference to the sales_order table
through the order_number column.
DELETE FROM sales_order;
INSERT INTO sales_order
VALUES ( order_number_sequence.nextval, 200.00 );
INSERT INTO order_details
VALUES ( order_number_sequence.currval, 1, 'End
Table',1, 100.00);
INSERT INTO order_details
VALUES ( order_number_sequence.currval, 2, 'Table
Lamp',2, 50.00);
SELECT * FROM sales_order;
ORDER_NUMBER ORDER_AMOUNT
------------ ------------
5 200
SELECT *
FROM order_details;
ORDER_NUMBER ORDER_ROW PRODUCT_DESC QUANTITY_ORDERED
PRODUCT_PRICE
--------- -------- ---------- ------------- ----------
5 1 End Table 1 100
5 2 Table Lamp 2 50
ALTERING A SEQUENCE
• A sequence is usually altered when it is desirable to
set or eliminate the values of the MINVALUE or
MAXVALUE parameters, or to change the
INCREMENT BY value, or to change the number of
cached sequence numbers.
• The ALTER SEQUENCE command shown here
changes the MAXVALUE of the
order_number_sequence to 200,000,000.
ALTER SEQUENCE order_number_sequence MAXVALUE
200000000;
ALTERING A SEQUENCE
• When specifying a MINVALUE clause, the
specified value should be less than the
MAXVALUE where a sequence generates
ascending numbers.
• In the case of a descending sequence, the
MAXVALUE should be less than the
MINVALUE.
VIEWING SEQUENCE PROPERTIES
• You may need to review the names and
properties of your sequences.
• You can do this by querying the
USER_SEQUENCES system view with a SELECT
command.This view is part of the database's
data dictionary.
SELECT * FROM USER_SEQUENCES;
SEQUENCE_NAME MIN_VAL MAX_VALUE INCRE C O
CACHE_SIZE Last_N
---------------- ------ ---------- ----- -- -- --------
-----
ORDER_NUMBER_SEQUENCE 1 200000000 1 Y N 10 6
DROPPING A SEQUENCE
• DROP SEQUENCE command is used to drop
sequences that need to be recreated or are
no longer needed.
• The general format is shown here along with
an example that drops the
order_number_sequence object.
DROP SEQUENCE <sequence name>;
DROP SEQUENCE order_number_sequence;
Sequence dropped.
Q&A
Ad

Recommended

Sequences and indexes
Sequences and indexes
Balqees Al.Mubarak
 
Sql operators & functions 3
Sql operators & functions 3
Dr. C.V. Suresh Babu
 
Database Objects
Database Objects
Salman Memon
 
SQL
SQL
Vineeta Garg
 
sql function(ppt)
sql function(ppt)
Ankit Dubey
 
Dbms slides
Dbms slides
rahulrathore725
 
Sql commands
Sql commands
Pooja Dixit
 
Chapter 3 stored procedures
Chapter 3 stored procedures
baabtra.com - No. 1 supplier of quality freshers
 
Basic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
introdution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
SQL Joins.pptx
SQL Joins.pptx
Ankit Rai
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
MSB Academy
 
View & index in SQL
View & index in SQL
Swapnali Pawar
 
AGGREGATE FUNCTION.pptx
AGGREGATE FUNCTION.pptx
Anusha sivakumar
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
Edureka!
 
Joins in SQL
Joins in SQL
Vigneshwaran Sankaran
 
SQL Overview
SQL Overview
Stewart Rogers
 
Sql subquery
Sql subquery
Raveena Thakur
 
Sql clauses by Manan Pasricha
Sql clauses by Manan Pasricha
MananPasricha
 
SQL Views
SQL Views
baabtra.com - No. 1 supplier of quality freshers
 
Sql commands
Sql commands
Balakumaran Arunachalam
 
SQL JOINS
SQL JOINS
Swapnali Pawar
 
SQL - DML and DDL Commands
SQL - DML and DDL Commands
Shrija Madhu
 
05 Creating Stored Procedures
05 Creating Stored Procedures
rehaniltifat
 
SQL Commands
SQL Commands
Sachidananda M H
 
SQL select clause
SQL select clause
arpit bhadoriya
 
Basic SQL and History
Basic SQL and History
SomeshwarMoholkar
 
SEQUNCES Lecture_Notes_Unit4_chapter11_sequence
SEQUNCES Lecture_Notes_Unit4_chapter11_sequence
Murugan Solaiyappan
 
Sequences
Sequences
avniS
 

More Related Content

What's hot (20)

Basic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
introdution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
SQL Joins.pptx
SQL Joins.pptx
Ankit Rai
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
MSB Academy
 
View & index in SQL
View & index in SQL
Swapnali Pawar
 
AGGREGATE FUNCTION.pptx
AGGREGATE FUNCTION.pptx
Anusha sivakumar
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
Edureka!
 
Joins in SQL
Joins in SQL
Vigneshwaran Sankaran
 
SQL Overview
SQL Overview
Stewart Rogers
 
Sql subquery
Sql subquery
Raveena Thakur
 
Sql clauses by Manan Pasricha
Sql clauses by Manan Pasricha
MananPasricha
 
SQL Views
SQL Views
baabtra.com - No. 1 supplier of quality freshers
 
Sql commands
Sql commands
Balakumaran Arunachalam
 
SQL JOINS
SQL JOINS
Swapnali Pawar
 
SQL - DML and DDL Commands
SQL - DML and DDL Commands
Shrija Madhu
 
05 Creating Stored Procedures
05 Creating Stored Procedures
rehaniltifat
 
SQL Commands
SQL Commands
Sachidananda M H
 
SQL select clause
SQL select clause
arpit bhadoriya
 
Basic SQL and History
Basic SQL and History
SomeshwarMoholkar
 

Similar to Oracle Database Sequence (20)

SEQUNCES Lecture_Notes_Unit4_chapter11_sequence
SEQUNCES Lecture_Notes_Unit4_chapter11_sequence
Murugan Solaiyappan
 
Sequences
Sequences
avniS
 
chap13.ppt
chap13.ppt
MuhammadAbubakar114879
 
Les13[1]Other Database Objects
Les13[1]Other Database Objects
siavosh kaviani
 
e computer notes - Other database objects
e computer notes - Other database objects
ecomputernotes
 
Les13
Les13
arnold 7490
 
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
consravs
 
SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13
Umair Amjad
 
Les12
Les12
Vijay Kumar
 
Oracle: DDL
Oracle: DDL
DataminingTools Inc
 
Oracle: Commands
Oracle: Commands
oracle content
 
Less08_Schema Advanced Databases and Management.pptx
Less08_Schema Advanced Databases and Management.pptx
MurtazaMughal13
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
Raviteja Chowdary Adusumalli
 
Sequencereset
Sequencereset
oracle documents
 
Oracle 10g
Oracle 10g
Svetlin Nakov
 
Part 7 alter sequence modified
Part 7 alter sequence modified
Girija Muscut
 
data base programming chapter1 26 slides
data base programming chapter1 26 slides
nights1988
 
2 sql - single-row functions
2 sql - single-row functions
Ankit Dubey
 
Oracle 11G SQL 2nd Edition Casteel Test Bank
Oracle 11G SQL 2nd Edition Casteel Test Bank
precyimael
 
SEQUNCES Lecture_Notes_Unit4_chapter11_sequence
SEQUNCES Lecture_Notes_Unit4_chapter11_sequence
Murugan Solaiyappan
 
Sequences
Sequences
avniS
 
Les13[1]Other Database Objects
Les13[1]Other Database Objects
siavosh kaviani
 
e computer notes - Other database objects
e computer notes - Other database objects
ecomputernotes
 
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
consravs
 
SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13
Umair Amjad
 
Less08_Schema Advanced Databases and Management.pptx
Less08_Schema Advanced Databases and Management.pptx
MurtazaMughal13
 
Part 7 alter sequence modified
Part 7 alter sequence modified
Girija Muscut
 
data base programming chapter1 26 slides
data base programming chapter1 26 slides
nights1988
 
2 sql - single-row functions
2 sql - single-row functions
Ankit Dubey
 
Oracle 11G SQL 2nd Edition Casteel Test Bank
Oracle 11G SQL 2nd Edition Casteel Test Bank
precyimael
 
Ad

More from Eryk Budi Pratama (20)

ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
Eryk Budi Pratama
 
Digital Leadership: How to Build Valuable Connection
Digital Leadership: How to Build Valuable Connection
Eryk Budi Pratama
 
AI Solutions for Sustainable Developmentpment_public.pdf
AI Solutions for Sustainable Developmentpment_public.pdf
Eryk Budi Pratama
 
AI Governance: Responsible and Trustworthy AI
AI Governance: Responsible and Trustworthy AI
Eryk Budi Pratama
 
Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTI
Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTI
Eryk Budi Pratama
 
Implikasi UU PDP terhadap Tata Kelola Data Sektor Kesehatan - Rangkuman UU Pe...
Implikasi UU PDP terhadap Tata Kelola Data Sektor Kesehatan - Rangkuman UU Pe...
Eryk Budi Pratama
 
Privacy-ready Data Protection Program Implementation
Privacy-ready Data Protection Program Implementation
Eryk Budi Pratama
 
Cybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber Security
Eryk Budi Pratama
 
Personal Data Protection in Indonesia
Personal Data Protection in Indonesia
Eryk Budi Pratama
 
Urgensi RUU Perlindungan Data Pribadi
Urgensi RUU Perlindungan Data Pribadi
Eryk Budi Pratama
 
Modern IT Service Management Transformation - ITIL Indonesia
Modern IT Service Management Transformation - ITIL Indonesia
Eryk Budi Pratama
 
Common Practice in Data Privacy Program Management
Common Practice in Data Privacy Program Management
Eryk Budi Pratama
 
The Rise of Data Ethics and Security - AIDI Webinar
The Rise of Data Ethics and Security - AIDI Webinar
Eryk Budi Pratama
 
Data Protection Indonesia: Basic Regulation and Technical Aspects_Eryk
Data Protection Indonesia: Basic Regulation and Technical Aspects_Eryk
Eryk Budi Pratama
 
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
Eryk Budi Pratama
 
Cyber Resilience - Welcoming New Normal - Eryk
Cyber Resilience - Welcoming New Normal - Eryk
Eryk Budi Pratama
 
Enabling Data Governance - Data Trust, Data Ethics, Data Quality
Enabling Data Governance - Data Trust, Data Ethics, Data Quality
Eryk Budi Pratama
 
Enterprise Cybersecurity: From Strategy to Operating Model
Enterprise Cybersecurity: From Strategy to Operating Model
Eryk Budi Pratama
 
Blockchain for Accounting & Assurance
Blockchain for Accounting & Assurance
Eryk Budi Pratama
 
Guardians of Trust: Building Trust in Data & Analytics
Guardians of Trust: Building Trust in Data & Analytics
Eryk Budi Pratama
 
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
Eryk Budi Pratama
 
Digital Leadership: How to Build Valuable Connection
Digital Leadership: How to Build Valuable Connection
Eryk Budi Pratama
 
AI Solutions for Sustainable Developmentpment_public.pdf
AI Solutions for Sustainable Developmentpment_public.pdf
Eryk Budi Pratama
 
AI Governance: Responsible and Trustworthy AI
AI Governance: Responsible and Trustworthy AI
Eryk Budi Pratama
 
Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTI
Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTI
Eryk Budi Pratama
 
Implikasi UU PDP terhadap Tata Kelola Data Sektor Kesehatan - Rangkuman UU Pe...
Implikasi UU PDP terhadap Tata Kelola Data Sektor Kesehatan - Rangkuman UU Pe...
Eryk Budi Pratama
 
Privacy-ready Data Protection Program Implementation
Privacy-ready Data Protection Program Implementation
Eryk Budi Pratama
 
Cybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber Security
Eryk Budi Pratama
 
Personal Data Protection in Indonesia
Personal Data Protection in Indonesia
Eryk Budi Pratama
 
Urgensi RUU Perlindungan Data Pribadi
Urgensi RUU Perlindungan Data Pribadi
Eryk Budi Pratama
 
Modern IT Service Management Transformation - ITIL Indonesia
Modern IT Service Management Transformation - ITIL Indonesia
Eryk Budi Pratama
 
Common Practice in Data Privacy Program Management
Common Practice in Data Privacy Program Management
Eryk Budi Pratama
 
The Rise of Data Ethics and Security - AIDI Webinar
The Rise of Data Ethics and Security - AIDI Webinar
Eryk Budi Pratama
 
Data Protection Indonesia: Basic Regulation and Technical Aspects_Eryk
Data Protection Indonesia: Basic Regulation and Technical Aspects_Eryk
Eryk Budi Pratama
 
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
Eryk Budi Pratama
 
Cyber Resilience - Welcoming New Normal - Eryk
Cyber Resilience - Welcoming New Normal - Eryk
Eryk Budi Pratama
 
Enabling Data Governance - Data Trust, Data Ethics, Data Quality
Enabling Data Governance - Data Trust, Data Ethics, Data Quality
Eryk Budi Pratama
 
Enterprise Cybersecurity: From Strategy to Operating Model
Enterprise Cybersecurity: From Strategy to Operating Model
Eryk Budi Pratama
 
Blockchain for Accounting & Assurance
Blockchain for Accounting & Assurance
Eryk Budi Pratama
 
Guardians of Trust: Building Trust in Data & Analytics
Guardians of Trust: Building Trust in Data & Analytics
Eryk Budi Pratama
 
Ad

Recently uploaded (20)

You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 

Oracle Database Sequence

  • 1. E R Y K B U D I P R A T A M A T I F L A B A S S I S T A N T – I N F O R M A T I C S E N G I N E E R I N G ORACLE DATABASE SEQUENCE
  • 2. DEFINITION • Just like tables, views, indexes, and synonyms, a sequence is a type of database object. • Sequences are used to generate unique, sequential integer values that are used as primary key values in database tables. • The sequence of numbers can be generated in either ascending or descending order.
  • 3. SEQUENCE SYNTAX CREATE SEQUENCE <sequence name> [INCREMENT BY <number>] [START WITH <start value number>] [MAXVALUE <MAXIMUM VLAUE NUMBER>] [NOMAXVALUE] [MINVALUE <minimum value number>] [CYCLE] [NOCYCLE] [CACHE <number of sequence value to cache>] [NOCACHE] [ORDER] [NOORDER];
  • 4. EXAMPLE CREATE SEQUENCE order_number_sequence INCREMENT BY 1 START WITH 1 MAXVALUE 100000000 MINVALUE 1 CYCLE CACHE 10; Sequence created.
  • 5. ACCESSING SEQUENCE VALUES • Sequence values are generated through the use of two pseudocolumns named currval and nextval. • A pseudocolumn behaves like a table column, but psuedocolumns are not actually stored in a table. • We can select values from pseudocolumns but cannot perform manipulations on their values. • The first time you select the nextval pseudocolumn, the initial value in the sequence is returned. • Subsequent selections of the nextval pseudocolumn will cause the sequence to increment as specified by the INCREMENT BY clause and will return the newly generated sequence value.
  • 6. • The currval pseudocolumn returns the current value of the sequence, which is the value returned by the last reference to nextval. Example CREATE TABLE sales_order ( order_number NUMBER(9) CONSTRAINT pk_sales_order PRIMARY KEY, order_amount NUMBER(9,2));
  • 7. • The INSERT commands shown below insert three rows into the sales_order table. The INSERT commands reference the order_number_sequence.nextval pseudocolumn. INSERT INTO sales_order VALUES(order_number_sequence.nextval, 155.59 ); INSERT INTO sales_order VALUES(order_number_sequence.nextval, 450.00 ); INSERT INTO sales_order VALUES(order_number_sequence.nextval, 16.95);
  • 8. SELECT * FROM sales_order; ORDER_NUMBER ORDER_AMOUNT ------------ ------------ 1 155.59 2 450 3 16.95
  • 9. • Use of currval. CREATE TABLE order_details ( order_number NUMBER(9), order_row NUMBER(3), product_desc VARCHAR2(15), quantity_ordered NUMBER(3), product_price NUMBER(9,2), CONSTRAINT pk_order_details PRIMARY KEY (order_number, order_row), CONSTRAINT fk_order_number FOREIGN KEY (order_number) REFERENCES sales_order);
  • 10. • The order_details table has a FOREIGN KEY reference to the sales_order table through the order_number column. DELETE FROM sales_order; INSERT INTO sales_order VALUES ( order_number_sequence.nextval, 200.00 ); INSERT INTO order_details VALUES ( order_number_sequence.currval, 1, 'End Table',1, 100.00); INSERT INTO order_details VALUES ( order_number_sequence.currval, 2, 'Table Lamp',2, 50.00);
  • 11. SELECT * FROM sales_order; ORDER_NUMBER ORDER_AMOUNT ------------ ------------ 5 200 SELECT * FROM order_details; ORDER_NUMBER ORDER_ROW PRODUCT_DESC QUANTITY_ORDERED PRODUCT_PRICE --------- -------- ---------- ------------- ---------- 5 1 End Table 1 100 5 2 Table Lamp 2 50
  • 12. ALTERING A SEQUENCE • A sequence is usually altered when it is desirable to set or eliminate the values of the MINVALUE or MAXVALUE parameters, or to change the INCREMENT BY value, or to change the number of cached sequence numbers. • The ALTER SEQUENCE command shown here changes the MAXVALUE of the order_number_sequence to 200,000,000. ALTER SEQUENCE order_number_sequence MAXVALUE 200000000;
  • 13. ALTERING A SEQUENCE • When specifying a MINVALUE clause, the specified value should be less than the MAXVALUE where a sequence generates ascending numbers. • In the case of a descending sequence, the MAXVALUE should be less than the MINVALUE.
  • 14. VIEWING SEQUENCE PROPERTIES • You may need to review the names and properties of your sequences. • You can do this by querying the USER_SEQUENCES system view with a SELECT command.This view is part of the database's data dictionary. SELECT * FROM USER_SEQUENCES; SEQUENCE_NAME MIN_VAL MAX_VALUE INCRE C O CACHE_SIZE Last_N ---------------- ------ ---------- ----- -- -- -------- ----- ORDER_NUMBER_SEQUENCE 1 200000000 1 Y N 10 6
  • 15. DROPPING A SEQUENCE • DROP SEQUENCE command is used to drop sequences that need to be recreated or are no longer needed. • The general format is shown here along with an example that drops the order_number_sequence object. DROP SEQUENCE <sequence name>; DROP SEQUENCE order_number_sequence; Sequence dropped.
  • 16. Q&A