Oracle中没有sqlserver中那么方便的自增序列,如果想要达到sqlserver中那种效果,也不是很麻烦,需要创建一个自增序列SEQUENCE,
Oracle中没有sqlserver中那么方便的自增序列,如果想要达到sqlserver中那种效果,也不是很麻烦,需要创建一个自增序列SEQUENCE,然后建一个触发器即可。
CREATE SEQUENCE emp_sequence
INCREMENT BY 1 -- 自增步长,这里步长是1
START WITH 1 -- 从1开始计数
NOMAXvalue -- 不设置最大值,如果要设置最大值,就是MAXvalue 后面跟想要设置的值
NOCYCLE -- 一直累加,不循环
NOCACHE ; --不设置缓存,如果要设置的话,,格式同MAXvalue
定义了emp_sequence,你就可以用CURRVAL,NEXTVAL。CURRVAL=返回 sequence的当前值,NEXTVAL=增加sequence的值,然后返回 sequence 值。
比如:
emp_sequence.CURRVAL ,emp_sequence.NEXTVAL
可以使用sequence的地方:
不包含子查询、snapshot和view的 SELECT 语句
INSERT语句的子查询中
NSERT语句的values中
UPDATE 的 set中
注意:
第一次NEXTVAL返回的是初始值;随后的NEXTVAL会自动增加你定义的步长,然后返回增加后的值。CURRVAL 总是返回当前SEQUENCE的值,但是在第一次NEXTVAL初始化之后才能使用CURRVAL,否则会出错。一次NEXTVAL会增加一次 SEQUENCE的值,所以如果你在同一个语句里面使用多个NEXTVAL,他们的值就是不一样的。
如果指定cache值,Oracle就可以预先在内存里面放置一些sequence,这样存取的快些。cache里面的取完后,Oracle自动再取一组到cache。 使用cache或许会跳号, 比如数据库突然不正常down掉(shutdown abort),cache中的sequence就会丢失. 所以可以在create sequence的时候用nocache防止这种情况。
修改或者删除Sequence跟对数据表的操作一样,用alter和drop。

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
