CREATE OR REPLACE
procedure UpdateSHGL_CJForDate(
 i_cjrq in date
)
as 
-------------------------
cursor dataForDate isselect HM,HMLB,BDHF,BDCT,BDGJ,YHL from SHGL_CJQD 
where CJRQ=changedDate;
这个changedDate是i_cjrq的处理,可是是我现在想在定义游标之前用
---------------------------select to_char(i_cjrq,'YYYY-MM') into changeStrDate from dual;
 select to_date(changeStrDate,'YYYY-MM') into changedDate from dual;
-------------------------------
对i_cjrq进行处理怎么办一得到changedDate??怎么办谢谢!!!!

解决方案 »

  1.   

    select   trunc(i_cjrq)   into   changedDate   from   dual; 
    是要这个吗?其实也没看太明白你的意思
      

  2.   

    我的意思是要对游标中的changedDate进行处理,而处理语句就是
    ---------------
    select   to_char(i_cjrq,'YYYY-MM')   into   changeStrDate   from   dual; 
      select   to_date(changeStrDate,'YYYY-MM')   into   changedDate   from   dual; 
    -------但是执行两条select必须是在定义游标之前,现在就会出错.不允许,如过把两个select那在后面来的话
    有不能对i_cjrq进行处理得到changeStrDate??现在怎么办?????
      

  3.   

    @sasacat这是我现在的代码:
    create or replace procedure UpdateSHGL_CJForDate(
     i_cjrq in date
    )
    as 
     type P_CURSOR is ref cursor;
     dataForDate   P_CURSOR;  
     h1  number(10,2):=0.49;--公话号码设备比率--号码
     s1  number(10,2):=0.41;--公话号码设备比率--设备
     h2  number(10,2):=0.25;--商话号码设备比率--号码
     s2  number(10,2):=0.25;--商话号码设备比率--设备
     A1  number(10,2);--国内话费
     B1  number(10,2);--国际话费
     C1  number(10,2);--国内长途话费
     D1  number(10,2);--优惠率
     F1  int:=100000;
     G1  int:=100;
     I1  number(10,2):=0.05;
     F2  int:=200000;
     G2  int:=100;
     I2  number(10,2):=0.10;
     E1  int:=30;
     E2  int:=60;
     i_yfcj number(10,2):=0.00;
     i_hmcj number(10,2):=0.00;
     i_sbcj number(10,2):=0.00;
     i_dlsbh number:=0;
     i_sbdls number:=0;
     total1  number(10,2);--话费合计
     total2  number(10,2);--长途话费合计
     total3  number(10,2);--扣除优惠和话费
     changeStrDate varchar(10);--转换日期字符集
     changedDate date;--改变后的日期
    begin
    --------------------------------------------
     --------------------------
     select to_char(i_cjrq,'YYYY-MM') into changeStrDate from dual;
     select to_date(changeStrDate,'YYYY-MM') into changedDate from dual;
     ---------------------------
    ---------------------------------------
      open dataForDate for select HM,HMLB,BDHF,BDCT,BDGJ,YHL from SHGL_CJQD 
      where CJRQ=i_cjrq;-------------------------------两句有错
      for r1 in dataForDate loop-----------------------------错
      A1:=r1.BDHF;
      B1:=r1.BDCT;
      C1:=r1.BDGJ;
      D1:=r1.YHL;
    -----------------------------------------------------------------------------
    select sum(DLSBH) into i_dlsbh from SHGL_CJQD where CJRQ=i_cjrq;--代理商编号
    select sum(DLSBH_SB) into i_sbdls  from SHGL_CJQD where CJRQ=i_cjrq;--设备代理商编号
    ------------------------------------------
     total1 :=A1+B1+C1;--话费合计
     total2 :=C1+(1/(3*B1));--长途话费合计
     total3 :=(1-D1)*total1;--扣除优惠和话费
    ------------------------------------------
    if r1.HMLB='1' then
     begin
      if (total2 >=E1) then
      begin
       i_hmcj:=H1 * total3;
       i_sbcj:=S1* total3;
      end;
      end if;
     end;
    end if;
    -----------------------------------------
    if r1.HMLB='2' then --2
       if total1>=F2 then--2.1
        if total1 >= G2 then--2.1.1
         i_hmcj:=(H2+I2)*total1;
         i_sbcj:=S2*total1;
        end if;
        if (total2>=E2 and total1<G2) or (i_dlsbh=i_sbdls) then--2.1.2
         i_hmcj:=H2*total1;
         i_sbcj:=S2*total1;
        end if; 
       end if;
      if total1 >= F1 and total1 < F2 then--2.2
        if (total1 >=G1) then--2.2.1
        begin
         i_hmcj:= (H2+I1) * total1;
         i_sbcj:= S2 * total1;
        end;
        end if;
        if (total2>=E2 and  total2<G1)or (i_dlsbh=i_sbdls) then--2.2.2
        begin
         i_hmcj:=H2 * total1;
         i_sbcj:=S2*total1;
        end;
        end if;
       end if; 
       if total1<F1 then--2.3
        begin
        i_hmcj:=H2 * total1;
        i_sbcj:=S2*total1;
        end;
       end if;--end2.3
    end if;
     --------------------------
    if i_dlsbh=i_sbdls then--3
     begin
      i_yfcj:=i_hmcj+i_sbcj;
     end;
    else 
     begin
      i_yfcj:=i_hmcj;
     end;
    end if;
    -------------------------------------
     update SHGL_CJQD
     set TOTAL=total1,
         YFCJ=i_yfcj, 
         HMCJ=i_hmcj,
         SBCJ=i_sbcj
     where HM=r1.HM;
     end loop;
    end;
    你看怎么该下
      

  4.   

    提示:PROCEDURE SHGL_ADMIN.UPDATESHGL_CJFORDATE 编译错误错误:PLS-00221: 'DATAFORDATE' 不是过程或尚未定义
    行:42
    文本:for r1 in dataForDate loop错误:PL/SQL: Statement ignored
    行:42
    文本:for r1 in dataForDate loop
    ----------
    谢谢!!!!!!!!!!
      

  5.   

    这两句好象没什么意义吧,
      select   to_char(i_cjrq,'YYYY-MM')   into   changeStrDate   from   dual; 
      select   to_date(changeStrDate,'YYYY-MM')   into   changedDate   from   dual;你下面的程序也没有用到changedDate这个变量啊
      

  6.   

    r1也要定义????
     open   dataForDate   for   select   HM,HMLB,BDHF,BDCT,BDGJ,YHL   from   SHGL_CJQD   
        where   CJRQ=i_changedDate  ;-------------------------------两句有错 
        for   r1   in   dataForDate   loop  
    但是还是包错.
    r1怎么定义,我定义了还是出错!可能是我不知道怎么定义??r1怎么定义???   
      

  7.   

    对照着改一下CREATE OR REPLACE PROCEDURE updateshgl_cjfordate (i_cjrq IN DATE)
    AS
       TYPE p_cursor IS REF CURSOR;
       datafordate   p_cursor;
       i_id number;
       sname varchar2(10);
    BEGIN
       OPEN datafordate FOR
          SELECT ID, NAME
            FROM test_a
           WHERE dddd = trunc(i_cjrq);   LOOP
          FETCH datafordate
           INTO i_ID, sNAME;
          EXIT WHEN datafordate%NOTFOUND;
    ---------------------换成你的具体处理过程-----      DBMS_OUTPUT.put_line (i_ID);
    --------------------
       END LOOP;   CLOSE datafordate;
    END;
      

  8.   

    sasacat谢谢了,我已经换了,可是在调试的时候说我数值精度太高??是什么意识
    ----------------
    如下改动:
     i_hm number(10,2);
     i_hmlb number(10,2);
     i_bdhf number(10,2);
     i_bdct number(10,2);
     i_bdgj number(10,2);
     i_yhl number(10,2);
    --------------游标改动
     open dataForDate for select HM,HMLB,BDHF,BDCT,BDGJ,YHL from SHGL_CJQD 
      where CJRQ=changedDate;
      loop fetch dataForDate into i_hm,i_hmlb,i_bdhf,i_bdct,i_bdgj,i_yhl ;---这里说我的数值精度太高!!
      exit when dataForDate%notfound;
    --------------