要达到的效果是:先查询数据库,如果已经存在,就更新,没有就插入

解决方案 »

  1.   

    test number;select count(*) into test from 你要查询的table;if test > 0 then
    你要操作的dml语句end if;
      

  2.   

    MERGE INTO cj_data_anal a
    using cj_data_anal_7 b
    on (a.curr_date = b.curr_date and a.pack_id = b.pack_id)
    WHEN MATCHED THEN  update set a.inst7_count = b.inst_count,a.act7_count = b.act_countWHEN NOT MATCHED THEN insert (a.curr_date,a.pack_id,a.inst7_count,a.act7_count)
    values (b.curr_date,b.pack_id,b.inst_count,b.act_count);
    完整的例子,具体用法可以goolge
      

  3.   

    --下面这个题是不是满足你的要求,我是有emp表
    /*编写一个过程,可以输入一个雇员名,如果该雇员补助不是0
     就在原来的基础上增加100;如果补助为0,就把补助设为200*/create procedure sp_pro7 (spname emp.ename%type) 
     is
     sp_comm emp.comm%type;
     begin
     select comm into sp_comm from emp where ename=spname;
     if sp_comm<>0 then
     update emp set comm=comm+100 where ename=spname;
     else 
     update emp set comm=200 where ename=spname;
     end if;
     end;
     / 
      exec sp_pro7('SCOTT');
      

  4.   

    LZ说的应该是程序里如何判断
    判断返回结果行数是方法之一。
    曾经用MFC编写程序的时候被此问题困扰过
      

  5.   


    select a.source_line_id
          ,a.pac_period_id
          ,a.vendor_id
          ,a.inventory_item_id
          ,a.amount
          ,a.memo
      from tg_purchase_acc_sl_line a  ;
      

  6.   

    select a.source_line_id
          ,a.pac_period_id
          ,a.vendor_id
          ,a.inventory_item_id
          ,a.jine
      from sl_check_temp a;
      

  7.   

    sl_check_temp 这是一张临时表