drop trigger "tib_brand"
/
drop table BRAND cascade constraints
/
/*==============================================================*/
/* Table: BRAND */
/*==============================================================*/
create table BRAND
(
BRAND_ID NUMBER(11) not null,
BRAND_NAME VARCHAR2(80 CHAR),
BRAND_DESC VARCHAR2(80 CHAR),
IMGS VARCHAR(100),
WEBSITE VARCHAR(240),
BRAND_SORT NUMBER(5),
constraint PK_BRAND primary key (BRAND_ID)
)
/
comment on table BRAND is
'UM品牌表'
/
create sequence Sequence_1
increment by 1
start with 1
nomaxvalue
minvalue 1
nocache;
create trigger "tib_brand" before insert
on BRAND for each row
declare
integrity_error exception;
errno integer;
errmsg char(200);
dummy integer;
found boolean;
begin
-- Column "BRAND_ID" uses sequence Sequence_1
select Sequence_1.NEXTVAL INTO :new.BRAND_ID from dual;
-- Errors handling
exception
when integrity_error then
raise_application_error(errno, errmsg);
end;
/
insert into BRAND(BRAND_NAME) values('HELLO');
/
drop table BRAND cascade constraints
/
/*==============================================================*/
/* Table: BRAND */
/*==============================================================*/
create table BRAND
(
BRAND_ID NUMBER(11) not null,
BRAND_NAME VARCHAR2(80 CHAR),
BRAND_DESC VARCHAR2(80 CHAR),
IMGS VARCHAR(100),
WEBSITE VARCHAR(240),
BRAND_SORT NUMBER(5),
constraint PK_BRAND primary key (BRAND_ID)
)
/
comment on table BRAND is
'UM品牌表'
/
create sequence Sequence_1
increment by 1
start with 1
nomaxvalue
minvalue 1
nocache;
create trigger "tib_brand" before insert
on BRAND for each row
declare
integrity_error exception;
errno integer;
errmsg char(200);
dummy integer;
found boolean;
begin
-- Column "BRAND_ID" uses sequence Sequence_1
select Sequence_1.NEXTVAL INTO :new.BRAND_ID from dual;
-- Errors handling
exception
when integrity_error then
raise_application_error(errno, errmsg);
end;
/
insert into BRAND(BRAND_NAME) values('HELLO');
select * from brand;
查看自增长的值 :
select Sequence_1.NEXTVAL from dual;