描述: 
通过输入一个codeid 和日期,比较a和b表的某些字段的数据是否一致,a表和b表都有codeid和日期,把不一致的输出出来。

解决方案 »

  1.   

    类似与  a表的name字段  和b表的name字段是否一致表结构codeid
    time
    name
      

  2.   

    select a.col, b.col
      from a full outer join b
      on (a.codeid=b.codeid and a.datecol=b.datecol)
     where a.col is not null
       and b.col is not null
      

  3.   

    能保证 a、b 表根据 条件 codeid 与日期 查询的结果只有1条吗?
      

  4.   

    select ... , 'a' tablename from a where not exists(select 1 from b where ...)
    union all
    select ... , 'b' tablename from b where not exists(select 1 from a where ...)
      

  5.   

    同意5楼的写法,这个可以写个VIEW就行了
      

  6.   

    比如有a  b  2个表 a  b  中都有id  time字段 根据id  和time字段判断 2个表中的name字段的值是否一致,我想做一个存储过程,每次输入id和time字段,就可以查询出不一样的
      

  7.   

    create or replace function compare_data(p_id number, p_time date) return number  --返回1表示一样,0为不一样
    as
      v_res number;
      v_name a.name%type;
    begin
      select nullif(a.name, b.name)
        into v_name
        from a join b
          on(a.id=b.id and a.time=b.time)
         where a.id=p_id and a.time=p_time;
       if v_name is null then
          return 1;
       else
          return 0;
       end if;
      exception when others then
       return 0;
    end;
    /
      

  8.   

    也可以,如果是两个字段,可以这样(其中的address是a和b表都有的另外一个参与比较的字段)
    create or replace function compare_data(p_id number, p_time date) return number  --返回1表示一样,0为不一样 
    as 
      v_res number; 
      v_name a.name%type; 
    begin 
      select nullif(a.name||a.address, b.name||b.address
        into v_name 
        from a join b 
          on(a.id=b.id and a.time=b.time) 
        where a.id=p_id and a.time=p_time; 
      if v_name is null then 
          return 1; 
      else 
          return 0; 
      end if; 
      exception when others then 
      return 0; 
    end; 

      

  9.   

    create or replace function compare_data(p_id number, p_time date) return number  --返回1表示一样,0为不一样 
    as 
      v_res number;
      address varchar2; 
      v_name a.name%type; 
    begin 
      select nullif(a.name||a.address, b.name||b.address) 
        into v_name,address
        from a join b 
          on(a.id=b.id and a.time=b.time) 
        where a.id=p_id and a.time=p_time; 
      if v_name is null then 
          return 1; 
      else 
          return 0; 
      end if; 
      exception when others then 
      return 0; 
    end; 

    是这样吗?
      

  10.   


    上面的红色字是不用的
    nullif(a.name||a.address, b.name||b.address)只会得到一个值,而不是两个值,这里是把name和address组合在一起了.
    你可以用你的a表和b表试一试,实践最重要