自动增长列问题,在线等,急急急急急急急@~
创建表:
-- Create table
create table JR_KHZHYEGL
(
ID NUMBER not null,
HYDWNO VARCHAR2(30) not null,
QCJE VARCHAR2(50),
RJE VARCHAR2(50),
SHJE VARCHAR2(50),
FSDATE VARCHAR2(20),
CZYNO VARCHAR2(30),
LRDATE VARCHAR2(20),
CJE VARCHAR2(50)
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
-- Add comments to the columns
comment on column JR_KHZHYEGL.ID
is '客户主键';
comment on column JR_KHZHYEGL.QCJE
is '账户余额';
comment on column JR_KHZHYEGL.RJE
is '入账金额';
comment on column JR_KHZHYEGL.SHJE
is '赎货金额';
comment on column JR_KHZHYEGL.FSDATE
is '发生日期';
comment on column JR_KHZHYEGL.CZYNO
is '录入人员';
comment on column JR_KHZHYEGL.LRDATE
is '录入日期';
comment on column JR_KHZHYEGL.CJE
is '出账金额';
-- Create/Recreate primary, unique and foreign key constraints
alter table JR_KHZHYEGL
add constraint SYS_JR_KHZHYEGL primary key (ID)
using index
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
创建序列:
CREATE SEQUENCE jr_khzhyegl_id_seq
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
NOCACHE -- 不建缓冲区
创建触发器;
CREATE TRIGGER jr_khzhyegl_trigger BEFORE
INSERT ON jr_khzhyegl FOR EACH ROW WHEN(new.id is null)
begin
select jr_khzhyegl_id_seq.nextval into:new.id from dual;
end;
-------------------
插入语句:insert into jr_khzhyegl(hydwno,qcje,rje) values('05161','jskld','sdjsdl')
插入语句时报错:ORA-04098: 触发器 “wl201112.jr_khzhyegl_trigger” 无效且未通过重新确认
------解决方案--------------------
CREATE OR REPLACE TRIGGER jr_khzhyegl_trigger BEFORE
INSERT ON jr_khzhyegl
FOR EACH ROW when (new.ID is null)
begin
INSERT INTO TEST_USER AS select JR_KHZHYEGL_ID_SEQ.nextval into :new.ID from dual;
end;
你的jr_khzhyegl_trigger 还能编译通过啊?
------解决方案--------------------我估计你的执行语句里面有全角空格,你查查看
------解决方案--------------------SQL code
create or replace trigger jr_khzhyegl_trigger
before insert on jr_khzhyegl
for each row
when(new.id is null)
begin
select jr_khzhyegl_id_seq.nextval into :new.id from dual;
end jr_khzhyegl_trigger;