oracle 触发器怎么实现当在A表插入数据时,输出B表对应ID的行 120
2个回答
展开全部
我创建的两个表
create table Users(
UserName varchar2(8) primary key,
password varchar2(8) not null,
qxno int,
foreign key(qxno) references qx(qxno)
);
create table Student(
StudentName varchar2(8) primary key,
password varchar2(8) not null,
name varchar2(20),
sex varchar2(4),
age int,
qxno int,
foreign key(qxno) references qx(qxno),
constraint chk_age check (age>10 and age<100)
);
我要实现的功能是,在向users表中插入数据时,如果qxno值为3,就向student中插入数据
触发器如下
create or replace trigger insert_users_tea
after insert on users
for each row
when(new.qxno=2)
insert into teacher(teachername,password,qxno)
values(:new.username,:new.passWord,:new.qxno)
/
插入数据时,提示ORA-04091: 表 ZYUAN.STUDENT 发生了变化, 触发器/函数不能读它
ORA-06512: 在 "ZYUAN.INSERT_USERS_STU", line 1
ORA-04088: 触发器 'ZYUAN.INSERT_USERS_STU' 执行过程中出错
create table Users(
UserName varchar2(8) primary key,
password varchar2(8) not null,
qxno int,
foreign key(qxno) references qx(qxno)
);
create table Student(
StudentName varchar2(8) primary key,
password varchar2(8) not null,
name varchar2(20),
sex varchar2(4),
age int,
qxno int,
foreign key(qxno) references qx(qxno),
constraint chk_age check (age>10 and age<100)
);
我要实现的功能是,在向users表中插入数据时,如果qxno值为3,就向student中插入数据
触发器如下
create or replace trigger insert_users_tea
after insert on users
for each row
when(new.qxno=2)
insert into teacher(teachername,password,qxno)
values(:new.username,:new.passWord,:new.qxno)
/
插入数据时,提示ORA-04091: 表 ZYUAN.STUDENT 发生了变化, 触发器/函数不能读它
ORA-06512: 在 "ZYUAN.INSERT_USERS_STU", line 1
ORA-04088: 触发器 'ZYUAN.INSERT_USERS_STU' 执行过程中出错
追问
什么玩意儿啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询