Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Sequences

Updated on 2023-03-17 GMT+08:00

A sequence is an Oracle object used to generate a number sequence. This can be useful when you need to create an autonumber column to act as a primary key.

If MigSupportSequence is set to true (default), a sequence is created in the PUBLIC schema.

NOTE:
  • CACHE and ORDER cannot be migrated.
  • In Oracle, the maximum value of MAXVALUE can be set to 999999999999999999999999999. In GaussDB(DWS), the maximum value of MAXVALUE can be set to 9223372036854775807.
  • Before migrating a sequence, copy the content in the custom_scripts.sql file and paste it to execute the script in all the target databases. For details, see Migration Process.

Sequence

Input - CREATE SEQUENCE

1
2
3
4
5
6
7
CREATE SEQUENCE GROUP_DEF_SEQUENCE 
  minvalue 1 
  maxvalue 100000000000000000000
  start with 1152 
  increment by 1 
  cache 50 
  order; 

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
INSERT
     INTO
          PUBLIC.MIG_SEQ_TABLE (
               SCHEMA_NAME
               ,SEQUENCE_NAME
               ,START_WITH
               ,INCREMENT_BY
               ,MIN_VALUE
               ,MAX_VALUE
               ,CYCLE_I
               ,CACHE
               ,ORDER_I
          )
     VALUES (
          UPPER( current_schema ( ) )
          ,UPPER( 'GROUP_DEF_SEQUENCE' )
          ,1152
          ,1
          ,1
          ,9223372036854775807
          ,FALSE
          ,20
          ,FALSE
     )
;

SEQUENCE with NOCACHE

Input - CREATE SEQUENCE with NOCACHE

1
2
3
4
5
CREATE SEQUENCE customers_seq
 START WITH 1000
 INCREMENT BY   1
 NOCACHE
 NOCYCLE;

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
INSERT
     INTO
          PUBLIC.MIG_SEQ_TABLE (
               SCHEMA_NAME
               ,SEQUENCE_NAME
               ,START_WITH
               ,INCREMENT_BY
               ,MIN_VALUE
               ,MAX_VALUE
               ,CYCLE_I
               ,CACHE
               ,ORDER_I
          )
     VALUES (
          UPPER( current_schema ( ) )
          ,UPPER( 'customers_seq' )
          ,1000
          ,1
          ,1
          ,999999999999999999999999999
          ,FALSE
          ,20
          ,FALSE
     )
;

Input - CREATE SEQUENCE with a specified schema name

Input - CREATE SEQUENCE with a specified schema name

1
2
3
4
CREATE SEQUENCE scott.seq_customers
 START WITH 1000 INCREMENT BY 1
 MINVALUE 1000 MAXVALUE 999999999999999
 CACHE 20 CYCLE ORDER;

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
INSERT
     INTO
          PUBLIC.MIG_SEQ_TABLE (
               SCHEMA_NAME
               ,SEQUENCE_NAME
               ,START_WITH
               ,INCREMENT_BY
               ,MIN_VALUE
               ,MAX_VALUE
               ,CYCLE_I
               ,CACHE
               ,ORDER_I
          )
     VALUES (
          UPPER( 'scott' )
          ,UPPER( 'seq_customers' )
          ,1000
          ,1
          ,1000
          ,999999999999999
          ,TRUE
          ,20
          ,FALSE
     )
;

CREATE SEQUENCE with a Default Value

Input - SEQUENCE with a default value

1
CREATE SEQUENCE seq_orders;

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
INSERT
     INTO
          PUBLIC.MIG_SEQ_TABLE (
               SCHEMA_NAME
               ,SEQUENCE_NAME
               ,START_WITH
               ,INCREMENT_BY
               ,MIN_VALUE
               ,MAX_VALUE
               ,CYCLE_I
               ,CACHE
               ,ORDER_I
          )
     VALUES (
          UPPER( current_schema ( ) )
          ,UPPER( 'seq_orders' )
          ,1
          ,1
          ,1
          ,999999999999999999999999999
          ,FALSE
          ,20
          ,FALSE
     )
;

NEXTVAL

To migrate the NEXTVAL function, a custom function is provided for generating the next value based on increment_by, max_value, min_value, and cycle. During the installation, this function should be created in all the databases where the migration is to be performed.

NEXTVAL supports all GaussDB(DWS) versions.

NEXTVAL is a system function of Oracle and is not implicitly supported by GaussDB(DWS). To support this function, DSC creates a NEXTVAL function in the PUBLIC schema. The PUBLIC.NEXTVAL function is used in the migrated statements.

NOTE:

If MigSupportSequence is set to true, NEXTVAL is migrated to PUBLIC.NEXTVAL('[schema].sequence').

If MigSupportSequence is set to false, NEXTVAL is migrated to NEXTVAL('[schema].sequence').

Before migrating the NEXTVAL function, copy the content in the custom_scripts.sql file and paste it to execute the script in all the target databases. For details, see Migration Process.

Input - NEXTVAL

1
[schema.]sequence.NEXTVAL

Output

1
PUBLIC.nextval('[schema.]sequence')

Input - NEXTVAL

1
2
3
4
5
6
SELECT
          EMP_ID_SEQ.NEXTVAL INTO
               SEQ_NUM
          FROM
               dual
;

Output

1
2
3
4
5
6
SELECT
          PUBLIC.NEXTVAL ('EMP_ID_SEQ') INTO
               SEQ_NUM
          FROM
               dual
;

CURRVAL

To migrate the CURRVAL function, you can customize one to return the current value of a sequence. During the installation, this function should be created in all the databases where the migration is to be performed.

CURRVAL is a system function of Oracle and is not implicitly supported by GaussDB(DWS). To support this function, DSC creates a CURRVAL function in the PUBLIC schema. The PUBLIC.CURRVAL function is used in the migrated statements.

NOTE:

If MigSupportSequence is set to true, CURRVAL is migrated to PUBLIC.CURRVAL('[schema].sequence').

If MigSupportSequence is set to false, CURRVAL is migrated to CURRVAL('[schema].sequence').

Before migrating the NEXTVAL function, copy the content in the custom_scripts.sql file and paste it to execute the script in all the target databases. For details, see Migration Process.

Input - CURRVAL

1
[schema.]sequence.CURRVAL

Output

1
currval('[schema.]sequence')

Input - CURRVAL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
INSERT
     INTO
          Line_items_tab (
               Orderno
               ,Partno
               ,Quantity
          )
     VALUES (
          Order_seq.CURRVAL
          ,20321
          ,3
     )
;

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
INSERT
     INTO
          Line_items_tab (
               Orderno
               ,Partno
               ,Quantity
          ) SELECT
                    PUBLIC.CURRVAL ('Order_seq')
                    ,20321
                    ,3
;

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback