簡單的講exists本身的意思就是: "if 存在... then"
所以不必要在加if...then

解决方案 »

  1.   

    create or replace procedure data_import
    as
    num number;
    begin
    select count(*) into num from temp_yuangxx a where zhih exists(select zhih from tyuangxx b where a.zhih=b.zhih))
    if num>0 then
       insert into tyuangxx(zhih,xingb,bumh,gangwh,zhuangt,xingm,piaoxh,xianlcxdm)
       select zhih,rtrim(xingb)as xingb,bumh,gangwh,zhuangt,xingm,piaoxh,xianlcxdm from temp_yuangxx
       where zhih not in(select zhih from tyuangxx);end if;
    end;
      

  2.   

    觉得这是oracle比较笨的一个问题,它不允许IF Exists(select ...)的语法。用count(*)代替必然会带来性能的下降。因为IF Exists(select ...)可以在找到第一条记录的时候就返回真,而count(*)必须对全表进行扫描。
      

  3.   

    TO: gaoxiaospring(gaoxiaospring)
    说的好,它真的笨得死!我以前用SQL Server,写procedure得心应手,现在用oracle,想死了!在PL/SQL里写个小过程都出错。兄弟们有没有好书?望推荐几本,谢谢!
      

  4.   

    呵呵.多看看书就明白了!
    其实我看你们的想法就跟我一样,但我是觉得sqlserver笨得死.多学习是最重要
      

  5.   

    试试这样:
    create or replace procedure data_import
    as
    begin
       insert into tyuangxx(zhih,xingb,bumh,gangwh,zhuangt,xingm,piaoxh,xianlcxdm)
       select zhih,rtrim(xingb)as xingb,bumh,gangwh,zhuangt,xingm,piaoxh,xianlcxdm from temp_yuangxx
       where zhih not in(select zhih from tyuangxx) and 
       exists(select zhih from temp_yuangxx where zhih not in(select zhih from tyuangxx));
    end;