求SQL语句,我要写一个存储过程.
就是从表A里面查询出数据,然后用游标,一条一条的读取出来判断表B中是否存在这条数据,如果不存在就新增,如果存在,再判断下字段M是否一样,如果不一样就修改,如果一样就不操作.

解决方案 »

  1.   


    create or replace procedure pro_a
    is
    cnt number;
    cursor cur_a is select * from A;
    begin
    for rec in cur_a loopbegin --判断是否存在
    select 字段 into cnt from B 
    where B.字段=rec.字段;
    exception when no_data_found then
    insert into B values(rec.字段,rec.其他字段);
    commit;
    end;begin --判断字段M
    select 字段 into cnt from B 
    where B.字段=rec.字段
    and   B.字段M=rec.字段M;
    exception when no_data_found then
    做操作;
    end;end loop;
    end;
    /
      

  2.   

    声明部分改成:
    create or replace procedure pro_a
    is
    cnt A.字段%type;
    ......