Objective
This article gives you a major introduction to the method of creating a self-growing table in Oracle, which uses a sequence. Here's a few words, let's look at the sample code.
Sample code
CREATE TABLE Tb_student
(
ID number () not null,
createtime DATE not null,
Constraint Pk_tb_student primary key (ID)
);
Comment on table "tb_student" is
' student table ';
Comment on column "Tb_student". Id ' is
' primary key ID ';
Comment on column "Tb_student". Createtime ' is
' creation time ';
--Create sequence created
sequence seq_tb_student
minvalue 1
nomaxvalue start with
1 increment by
1
nocycle --cumulative, not cyclic
nocache;
--Creates a trigger if the INSERT statement does not specify an ID to automatically insert the growth value
create OR REPLACE TRIGGER tr_tb_student
before insert on tb_student for each ROW when (new.id are null)
begin
Select Seq_tb_student.nextval into:new.id from dual;
End
NOTE: triggers are not mandatory and can specify the insertion value from a strict business requirement.
Note that the Oracle Limit object name cannot be longer than 30 characters long, so the table name must be controlled at a certain length or the following creation sequence may exceed the limit, and it is recommended that the table name be controlled below 27 characters.
Summarize
The above is the Oracle to create the main table of the entire content, I hope the content of this article for everyone to learn or use Oracle to bring some help, if there are questions you can message exchange, small series will be as soon as possible to reply.