这里转摘了csdn中一个级联删除的例子,希对你有帮助:SQL> create table a (id varchar2(10),pid varchar2(10));Table created.SQL> alter table a add constraint pk_a primary key (id);Table altered.SQL> alter table a add constraint fk_a
2 foreign key (pid) references a(id)
3 on delete cascade;Table altered.SQL> select * from a;no rows selectedSQL> insert into a values ('1',null);1 row created.SQL> insert into a values ('2','1');1 row created.SQL> insert into a values ('3','1');1 row created.SQL> insert into a values ('4',null);1 row created.SQL> insert into a values ('5','3');1 row created.SQL> select * from a;ID PID
---------- ----------
1
2 1
3 1
4
5 3SQL> delete from a where id=1;1 row deleted.SQL> select * from a;ID PID
---------- ----------
4
2 foreign key (pid) references a(id)
3 on delete cascade;Table altered.SQL> select * from a;no rows selectedSQL> insert into a values ('1',null);1 row created.SQL> insert into a values ('2','1');1 row created.SQL> insert into a values ('3','1');1 row created.SQL> insert into a values ('4',null);1 row created.SQL> insert into a values ('5','3');1 row created.SQL> select * from a;ID PID
---------- ----------
1
2 1
3 1
4
5 3SQL> delete from a where id=1;1 row deleted.SQL> select * from a;ID PID
---------- ----------
4
如果要做级更新,用触发器可以办到
2 (head_no varchar2(10));
Table created.SQL> alter table t_head add constraint pk_t_head primary key (head_no);
Table altered.SQL> create table t_line
2 (head_no varchar2(10),
3 line_no number(10));
Table created.----- the most important thing to define a CASCADE UPDATE process is to -----
----- create a DEFERRABLE foreign key with initial status of DEFERRED -----
SQL> alter table t_line add constraint fk_t_line_t_head
2 foreign key (head_no)
3 references t_head (head_no)
4* deferrable initially deferred;
Table altered.SQL> create trigger trg_t_head_after_update
2 after update on t_head
3 for each row
4 begin
5 update t_line
6 set head_no=:new.head_no
7 where head_no=:old.head_no;
8 end;
9 /
Trigger created.SQL> insert into t_head values ('111');
1 row created.SQL> insert into t_head values ('222');
1 row created.SQL> insert into t_line values ('111',1);
1 row created.SQL> insert into t_line values ('111',2);
1 row created.SQL> insert into t_line values ('222',1);
1 row created.SQL> commit;
Commit complete.SQL> select * from t_head;
HEAD_NO
----------
111
222SQL> select * from t_line;
HEAD_NO LINE_NO
---------- ----------
111 1
111 2
222 1SQL> update t_head
2 set head_no='333'
3 where head_no='111';
1 row updated.SQL> select * from t_head;HEAD_NO
----------
333
222SQL> select * from t_line;HEAD_NO LINE_NO
---------- ----------
333 1
333 2
222 1