merge into pos_points a
using(select distinct(a.ac_id) ac_id,0 points,to_date(a.opn_date,'yyyymmdd') opn_date,c.br_name opn_br_no,a.name customer_name,d.id_no customer_id,
case when d.id_type='1' then '身份证'
     when d.id_type='2' then '户口簿'
     when d.id_type='3' then '护照'
     when d.id_type='4' then '军人证'
     when d.id_type='5' then '回乡证'
     when d.id_type='6' then '居住证'
     when d.id_type='7' then '驾照'
end id_type,0 count
from dd_mst@dhcc a,mdm_ac_rel@dhcc b,com_branch@dhcc c,cif_id_code_rel@dhcc d
where a.ac_id=b.ac_id and (mdm_code='0020' or mdm_code='0021')
and to_date(a.opn_date,'yyyy-mm-dd')=trunc(sysdate-1)
and a.opn_br_no=c.br_no  and a.cif_no=d.cif_no and d.id_type !='N') t
on(a.ac_id=t.ac_id)
when matched then 
update set a.points=a.points
when not matched then
insert values(t.ac_id,t.points,t.opn_date,t.opn_br_no,t.customer_name,t.customer_id,t.id_type,t.count);commit;insert into pointschange_rec select b.ac_id,a.ac_no,
case
 when a.stat='0' then
 0
 else
 1
end,a.tx_amt,to_date(a.tx_date,'yyyymmdd'),
to_date(case
    when a.stat='0' then
    ''
    else
    to_char(a.tx_date)
end,'yyyymmdd'),trunc(sysdate),a.mrchnm
from chnl_self_trade@dhcc a,mdm_ac_rel@dhcc b
where a.ttyp='2' 
and a.ac_no=b.ac_no
and to_date(tx_date,'yyyymmdd')=trunc(sysdate-1);commit;merge into pos_points a
using(select ac_id ac_id, trunc(sum(b.pcsum * (b.addreduce_flag*(-2)+1))) pnt_change,count(*) pcount from pointschange_rec b where b.pcdate=trunc(sysdate-1) group by b.ac_id) t
on(a.ac_id=t.ac_id)
when matched then
update set a.points=a.points+pnt_change,a.count=a.count + t.pcount
when not matched then
insert values (t.ac_id,t.pnt_change,sysdate,'','','','',pcount);commit;

解决方案 »

  1.   

    ...
    因为执行的都是dml语句,开头加上begin结尾加上end
    就是存储过程了
      

  2.   


    create or replace procedure pro_name
    is
    begin
    merge into pos_points a
    using(select distinct(a.ac_id) ac_id,0 points,to_date(a.opn_date,'yyyymmdd') opn_date,c.br_name opn_br_no,a.name customer_name,d.id_no customer_id,
    case when d.id_type='1' then '身份证'
         when d.id_type='2' then '户口簿'
         when d.id_type='3' then '护照'
         when d.id_type='4' then '军人证'
         when d.id_type='5' then '回乡证'
         when d.id_type='6' then '居住证'
         when d.id_type='7' then '驾照'
    end id_type,0 count
    from dd_mst@dhcc a,mdm_ac_rel@dhcc b,com_branch@dhcc c,cif_id_code_rel@dhcc d
    where a.ac_id=b.ac_id and (mdm_code='0020' or mdm_code='0021')
    and to_date(a.opn_date,'yyyy-mm-dd')=trunc(sysdate-1)
    and a.opn_br_no=c.br_no  and a.cif_no=d.cif_no and d.id_type !='N') t
    on(a.ac_id=t.ac_id)
    when matched then 
    update set a.points=a.points
    when not matched then
    insert values(t.ac_id,t.points,t.opn_date,t.opn_br_no,t.customer_name,t.customer_id,t.id_type,t.count);insert into pointschange_rec select b.ac_id,a.ac_no,
    case
     when a.stat='0' then
     0
     else
     1
    end,a.tx_amt,to_date(a.tx_date,'yyyymmdd'),
    to_date(case
        when a.stat='0' then
        ''
        else
        to_char(a.tx_date)
    end,'yyyymmdd'),trunc(sysdate),a.mrchnm
    from chnl_self_trade@dhcc a,mdm_ac_rel@dhcc b
    where a.ttyp='2' 
    and a.ac_no=b.ac_no
    and to_date(tx_date,'yyyymmdd')=trunc(sysdate-1);
    merge into pos_points a
    using(select ac_id ac_id, trunc(sum(b.pcsum * (b.addreduce_flag*(-2)+1))) pnt_change,count(*) pcount from pointschange_rec b where b.pcdate=trunc(sysdate-1) group by b.ac_id) t
    on(a.ac_id=t.ac_id)
    when matched then
    update set a.points=a.points+pnt_change,a.count=a.count + t.pcount
    when not matched then
    insert values (t.ac_id,t.pnt_change,sysdate,'','','','',pcount);commit;exception
       when others then
        raise;
    end pro_name;
      

  3.   

    我按2楼的方法进行了设置,但是为什么在plsql里用call不能执行呢?
    我执行了
    select * from user_procedures for update
    这条语句,
    结果是
    OBJECT_NAME    PROCEDURE_NAME AGGREGATE PIPELINED IMPLTYPEOWNER IMPLTYPENAME PARALLEL INTERFACE
    XP_PNTSCHANGE      NO       NO               NO     NO
    换句话说,这个procedure没有name,这是为什么呀
      

  4.   

    ..如果只是查询不要在结尾加上for update这个只读锁
    你试试execute PROCEDURENAME
      

  5.   

    select OBJECT_NAME from user_objects where OBJECT_TYPE = 'PROCEDURE';
      

  6.   

    如果查询数据字典找不到刚刚创建的存储过程,就是没有编译成功
    create or replace procedure.... end pro_name; 后要加上/符号,标志代码块结束,开始编译