查找a表中有,而在b表中没有的记录

  • 软件环境:
      1、Windows NT4.0+ORACLE 8.0.4
      2、ORACLE安装路径为:C:\ORANT
  • 实现方法:
    SQL> create table a (
      2  bm char(4),            --编码
      3  mc varchar2(20)            --名称
      4  )
      5  /
    
    表已建立.
    
    SQL> insert into a values('1111','1111');
    SQL> insert into a values('1112','1111');
    SQL> insert into a values('1113','1111');
    SQL> insert into a values('1114','1111');
    SQL> insert into a values('1115','1111');
    
    SQL> create table b as select * from a where 1=2;
    
    表已建立.
    
    SQL> insert into b values('1111','1111');
    SQL> insert into b values('1112','1111');
    SQL> insert into b values('1113','1111');
    SQL> insert into b values('1114','1111');
    
    
    SQL> commit;
    
    完全提交.
    
    
    SQL> select * from a;
    
    BM   MC
    ---- --------------------
    1111 1111
    1112 1111
    1113 1111
    1114 1111
    1115 1111
    
    SQL> select * from b;
    
    BM   MC
    ---- --------------------
    1111 1111
    1112 1111
    1113 1111
    1114 1111
    
    SQL> select bm from a where not exists (select bm from b where a.bm=b.bm);
    
    BM   MC
    ---- --------------------
    1115 1111
    

相关文章: