SlideShare uma empresa Scribd logo
1 de 16
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

Mais conteúdo relacionado

Mais procurados

Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sqlÑirmal Tatiwal
 
Introduction to Oracle Database
Introduction to Oracle DatabaseIntroduction to Oracle Database
Introduction to Oracle Databasepuja_dhar
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentationNITISH KUMAR
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbmsNaresh Kumar
 
Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Deepam Aggarwal
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts Bharat Kalia
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries InformationNishant Munjal
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)Sabana Maharjan
 
MySQL Architecture and Engine
MySQL Architecture and EngineMySQL Architecture and Engine
MySQL Architecture and EngineAbdul Manaf
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queriesPRAKHAR JHA
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Serverprogrammings guru
 

Mais procurados (20)

DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
Introduction to Oracle Database
Introduction to Oracle DatabaseIntroduction to Oracle Database
Introduction to Oracle Database
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
 
Triggers
TriggersTriggers
Triggers
 
Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
MySQL Architecture and Engine
MySQL Architecture and EngineMySQL Architecture and Engine
MySQL Architecture and Engine
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
 
advanced sql(database)
advanced sql(database)advanced sql(database)
advanced sql(database)
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 

Semelhante a Oracle Database Sequence (20)

Si0302 20140320131934
Si0302 20140320131934Si0302 20140320131934
Si0302 20140320131934
 
Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part I
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
Les13
Les13Les13
Les13
 
Sql wksht-3
Sql wksht-3Sql wksht-3
Sql wksht-3
 
MySQL-commands.pdf
MySQL-commands.pdfMySQL-commands.pdf
MySQL-commands.pdf
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
SQL Keywords
SQL KeywordsSQL Keywords
SQL Keywords
 
Dbms sql-final
Dbms  sql-finalDbms  sql-final
Dbms sql-final
 
Query
QueryQuery
Query
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
Views, Triggers, Functions, Stored Procedures,  Indexing and JoinsViews, Triggers, Functions, Stored Procedures,  Indexing and Joins
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
Sql
SqlSql
Sql
 
Lab
LabLab
Lab
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Sql functions
Sql functionsSql functions
Sql functions
 

Mais de Eryk Budi Pratama

Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTI
Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTIRingkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTI
Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTIEryk 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...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 ImplementationPrivacy-ready Data Protection Program Implementation
Privacy-ready Data Protection Program ImplementationEryk Budi Pratama
 
Cybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber SecurityCybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber SecurityEryk Budi Pratama
 
Personal Data Protection in Indonesia
Personal Data Protection in IndonesiaPersonal Data Protection in Indonesia
Personal Data Protection in IndonesiaEryk Budi Pratama
 
Urgensi RUU Perlindungan Data Pribadi
Urgensi RUU Perlindungan Data PribadiUrgensi RUU Perlindungan Data Pribadi
Urgensi RUU Perlindungan Data PribadiEryk Budi Pratama
 
Modern IT Service Management Transformation - ITIL Indonesia
Modern IT Service Management Transformation - ITIL IndonesiaModern IT Service Management Transformation - ITIL Indonesia
Modern IT Service Management Transformation - ITIL IndonesiaEryk Budi Pratama
 
Common Practice in Data Privacy Program Management
Common Practice in Data Privacy Program ManagementCommon Practice in Data Privacy Program Management
Common Practice in Data Privacy Program ManagementEryk Budi Pratama
 
The Rise of Data Ethics and Security - AIDI Webinar
The Rise of Data Ethics and Security - AIDI WebinarThe Rise of Data Ethics and Security - AIDI Webinar
The Rise of Data Ethics and Security - AIDI WebinarEryk Budi Pratama
 
Data Protection Indonesia: Basic Regulation and Technical Aspects_Eryk
Data Protection Indonesia: Basic Regulation and Technical Aspects_ErykData Protection Indonesia: Basic Regulation and Technical Aspects_Eryk
Data Protection Indonesia: Basic Regulation and Technical Aspects_ErykEryk Budi Pratama
 
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - ErykData Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - ErykEryk Budi Pratama
 
Cyber Resilience - Welcoming New Normal - Eryk
Cyber Resilience - Welcoming New Normal - ErykCyber Resilience - Welcoming New Normal - Eryk
Cyber Resilience - Welcoming New Normal - ErykEryk Budi Pratama
 
Enabling Data Governance - Data Trust, Data Ethics, Data Quality
Enabling Data Governance - Data Trust, Data Ethics, Data QualityEnabling Data Governance - Data Trust, Data Ethics, Data Quality
Enabling Data Governance - Data Trust, Data Ethics, Data QualityEryk Budi Pratama
 
Enterprise Cybersecurity: From Strategy to Operating Model
Enterprise Cybersecurity: From Strategy to Operating ModelEnterprise Cybersecurity: From Strategy to Operating Model
Enterprise Cybersecurity: From Strategy to Operating ModelEryk Budi Pratama
 
Blockchain for Accounting & Assurance
Blockchain for Accounting & AssuranceBlockchain for Accounting & Assurance
Blockchain for Accounting & AssuranceEryk Budi Pratama
 
Guardians of Trust: Building Trust in Data & Analytics
Guardians of Trust: Building Trust in Data & AnalyticsGuardians of Trust: Building Trust in Data & Analytics
Guardians of Trust: Building Trust in Data & AnalyticsEryk Budi Pratama
 
The Art of Cloud Auditing - ISACA ID
The Art of Cloud Auditing - ISACA IDThe Art of Cloud Auditing - ISACA ID
The Art of Cloud Auditing - ISACA IDEryk Budi Pratama
 
Cybersecurity Skills in Industry 4.0
Cybersecurity Skills in Industry 4.0Cybersecurity Skills in Industry 4.0
Cybersecurity Skills in Industry 4.0Eryk Budi Pratama
 
Identity & Access Management for Securing DevOps
Identity & Access Management for Securing DevOpsIdentity & Access Management for Securing DevOps
Identity & Access Management for Securing DevOpsEryk Budi Pratama
 
Cybersecurity in Oil & Gas Company
Cybersecurity in Oil & Gas CompanyCybersecurity in Oil & Gas Company
Cybersecurity in Oil & Gas CompanyEryk Budi Pratama
 

Mais de Eryk Budi Pratama (20)

Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTI
Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTIRingkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTI
Ringkasan Standar Kompetensi Data Protection Officer | Agustus 2023 | IODTI
 
Implikasi UU PDP terhadap Tata Kelola Data Sektor Kesehatan - Rangkuman UU Pe...
Implikasi UU PDP terhadap Tata Kelola Data Sektor Kesehatan - Rangkuman UU Pe...Implikasi UU PDP terhadap Tata Kelola Data Sektor Kesehatan - Rangkuman UU Pe...
Implikasi UU PDP terhadap Tata Kelola Data Sektor Kesehatan - Rangkuman UU Pe...
 
Privacy-ready Data Protection Program Implementation
Privacy-ready Data Protection Program ImplementationPrivacy-ready Data Protection Program Implementation
Privacy-ready Data Protection Program Implementation
 
Cybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber SecurityCybersecurity 101 - Auditing Cyber Security
Cybersecurity 101 - Auditing Cyber Security
 
Personal Data Protection in Indonesia
Personal Data Protection in IndonesiaPersonal Data Protection in Indonesia
Personal Data Protection in Indonesia
 
Urgensi RUU Perlindungan Data Pribadi
Urgensi RUU Perlindungan Data PribadiUrgensi RUU Perlindungan Data Pribadi
Urgensi RUU Perlindungan Data Pribadi
 
Modern IT Service Management Transformation - ITIL Indonesia
Modern IT Service Management Transformation - ITIL IndonesiaModern IT Service Management Transformation - ITIL Indonesia
Modern IT Service Management Transformation - ITIL Indonesia
 
Common Practice in Data Privacy Program Management
Common Practice in Data Privacy Program ManagementCommon Practice in Data Privacy Program Management
Common Practice in Data Privacy Program Management
 
The Rise of Data Ethics and Security - AIDI Webinar
The Rise of Data Ethics and Security - AIDI WebinarThe Rise of Data Ethics and Security - AIDI Webinar
The Rise of Data Ethics and Security - AIDI Webinar
 
Data Protection Indonesia: Basic Regulation and Technical Aspects_Eryk
Data Protection Indonesia: Basic Regulation and Technical Aspects_ErykData Protection Indonesia: Basic Regulation and Technical Aspects_Eryk
Data Protection Indonesia: Basic Regulation and Technical Aspects_Eryk
 
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - ErykData Loss Prevention (DLP) - Fundamental Concept - Eryk
Data Loss Prevention (DLP) - Fundamental Concept - Eryk
 
Cyber Resilience - Welcoming New Normal - Eryk
Cyber Resilience - Welcoming New Normal - ErykCyber Resilience - Welcoming New Normal - Eryk
Cyber Resilience - Welcoming New Normal - Eryk
 
Enabling Data Governance - Data Trust, Data Ethics, Data Quality
Enabling Data Governance - Data Trust, Data Ethics, Data QualityEnabling Data Governance - Data Trust, Data Ethics, Data Quality
Enabling Data Governance - Data Trust, Data Ethics, Data Quality
 
Enterprise Cybersecurity: From Strategy to Operating Model
Enterprise Cybersecurity: From Strategy to Operating ModelEnterprise Cybersecurity: From Strategy to Operating Model
Enterprise Cybersecurity: From Strategy to Operating Model
 
Blockchain for Accounting & Assurance
Blockchain for Accounting & AssuranceBlockchain for Accounting & Assurance
Blockchain for Accounting & Assurance
 
Guardians of Trust: Building Trust in Data & Analytics
Guardians of Trust: Building Trust in Data & AnalyticsGuardians of Trust: Building Trust in Data & Analytics
Guardians of Trust: Building Trust in Data & Analytics
 
The Art of Cloud Auditing - ISACA ID
The Art of Cloud Auditing - ISACA IDThe Art of Cloud Auditing - ISACA ID
The Art of Cloud Auditing - ISACA ID
 
Cybersecurity Skills in Industry 4.0
Cybersecurity Skills in Industry 4.0Cybersecurity Skills in Industry 4.0
Cybersecurity Skills in Industry 4.0
 
Identity & Access Management for Securing DevOps
Identity & Access Management for Securing DevOpsIdentity & Access Management for Securing DevOps
Identity & Access Management for Securing DevOps
 
Cybersecurity in Oil & Gas Company
Cybersecurity in Oil & Gas CompanyCybersecurity in Oil & Gas Company
Cybersecurity in Oil & Gas Company
 

Último

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 

Último (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

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