【发布时间】:2018-08-13 02:22:46
【问题描述】:
餐桌学院:
块引用
create table college
(
clg_code number(3) primary key,
clg_name varchar(20)
);
表 stud_detail
块引用
create table stud_detail
(
stud_no number(3) primary key,
name varchar(10),
dob date,
clg_code references college
);
我已经尝试过这个触发器,现在必须计算每个学院的学生总数。
块引用
set serveroutput on;
声明 cursor c_stud 是 select stud_no,name,clg_name from stud_detail s,college c where s.clg_code=c.clg_code;
v_stud c_stud%rowtype;
begin
for v_stud in c_stud
loop
dbms_output.put_line(v_stud.stud_no||' '||v_stud.name||' '||v_stud.clg_name);
end loop;
end;
/
大学表中的值
块引用
insert into college values (101,'Sahjanand');
insert into college values (102,'Gurukul');
insert into college values (103,'K.R.Doshi');
块引用
从大学中选择 *;
stud_detail 中的值
块引用
insert into stud_detail (name,dob,clg_code)values('abc','12-mar-1998',101);
insert into stud_detail (name,dob,clg_code)values('adsfbc','22-jan-1999',101);
insert into stud_detail (name,dob,clg_code)values('ac','13-feb-1995',101);
insert into stud_detail (name,dob,clg_code)values('ddbc','02-mar-1998',101);
insert into stud_detail (name,dob,clg_code)values('afdgc','09-sep-1996',101);
insert into stud_detail (name,dob,clg_code)values('adf','30-jun-1997',101);
insert into stud_detail (name,dob,clg_code)values('osif','24-mar-1996',101);
insert into stud_detail (name,dob,clg_code)values('dfif','13-mar-1996',102);
insert into stud_detail (name,dob,clg_code)values('odffif','26-jan-1993',102);
insert into stud_detail (name,dob,clg_code)values('fsaf','30-mar-1994',102);
insert into stud_detail (name,dob,clg_code)values('vvhgf','08-jul-1995',102);
insert into stud_detail (name,dob,clg_code)values('odgf','19-sep-1997',102);
insert into stud_detail (name,dob,clg_code)values('dfgfif','12-oct-1998',102);
insert into stud_detail (name,dob,clg_code)values('dfgdif','24-feb-1996',102);
insert into stud_detail (name,dob,clg_code)values('sdgfif','21-aug-1998',102);
insert into stud_detail (name,dob,clg_code)values('jc','22-mar-1994',103);
insert into stud_detail (name,dob,clg_code)values('charmi','26-dec-1998',103);
insert into stud_detail (name,dob,clg_code)values('ritu','04-dec-1991',103);
insert into stud_detail (name,dob,clg_code)values('ridddhi','26-may-1998',103);
insert into stud_detail (name,dob,clg_code)values('khushbu','11-jul-1998',103);
insert into stud_detail (name,dob,clg_code)values('vaishali','23-feb-1999',103);
块引用
从 stud_detail 中选择 *;
触发 stud_detail 的主键生成。
块引用
create or replace trigger tristud before insert on stud_detail for each row declare pkey number(5); begin select max(stud_no)+1 into pkey from stud_detail; if (pkey is null) then :new.stud_no:=1; else :new.stud_no:=pkey; end if; end; /
【问题讨论】:
标签: join plsql triggers plsqldeveloper cursors