入库表主表(入库编号,入库日期)  入库表从表(入库编号,物料编号,入库数量)   帐表(年,月,物料编号,期初数量,入库数量,库存量)  当填写入库表时,向帐表 中写入 年,月 ,物料 库存 信息 ,,请问如何写存储过程了。。用ORACLE 数据库
有例子的请给个例子,

解决方案 »

  1.   

    create or replace procedure pro(
       v_wid in varchar2,   -- 入库编号
       v_wdt in date,       -- 入库日期
       v_mid in varchar2,   -- 物料编号
       v_num in number)     -- 入库数量
    is
       v_stor   number;
       v_year   varchar2(20) := substr(to_char(v_wdt,'yyyymmdd'),1,4);
       v_month  varchar2(20) := substr(to_char(v_wdt,'yyyymmdd'),5,2);
    begin 
       insert into warehouse values(v_wid,v_wdt);
       insert into varehouse_pre values(v_wid,v_mid,v_num);   -- 获得库存量
       select stor into v_stor 
       from (select stor, row_number() over(order by year desc, month desc) rn 
             from   billtable )
       where rn = 1;
       
       insert into billtable values(v_year,v_month,v_mid,v_stor,v_num,v_num+v_stor);
       
       commit;
    exception
       when others then 
          raise;
    end pro;
    /注意column data type
      

  2.   

    create or replace trigger trig_input   
      after insert or update or delete on GSP_SStockIn
      for each row 
      declare spbh varchar2(20);
         jhdbh varchar2(20);
         rksl number(8);   
         v_year  varchar2(20);
         v_month  varchar2(20);
         i  date;
         ii  number;
     begin
      if inserting or updating then   
             spbh:=:new.SGD_Id;  
             rksl:=:new.SK_Num; 
               select SK_InPutTime into i  from GSP_SStockIn, GSP_MStockIn where GSP_SStockIn.SMSK_Id=GSP_MStockIn.MSK_Id and GSP_MStockIn.MSK_Id='jhdbh';
               v_year:= substr(to_char(i,'yyyymmdd'),1,4);
               v_month:= substr(to_char(i,'yyyymmdd'),5,2);
             select count(*) into ii from gsp_count   
             where CT_Year='v_year' and CT_Month='v_month' and CGD_Id='spbh';   
             if ii=0 then   
                    insert into GSP_Count(CGD_Id,CT_Year,CT_Month,CT_PreNum,CT_InPutNum,CT_OutPutNum,CT_FinalNum)   
                    value(spbh,v_year,v_month,0,0, rksl,rksl);   
             else  
                    update gsp_count   
                    set CT_InPutNum=CT_InPutNum+rksl, 
                   CT_FinalNum=CT_PreNum+CT_InPutNum;   
             end if;   
      end if; 
      if deleting or updating then   
             spbh:=:old.SGD_Id;   
                rksl:=:old.SK_Num;            update gsp_count            set CT_InPutNum=CT_InPutNum-rksl,  
               CT_FinalNum=CT_PreNum+CT_InPutNum;    
      end if;     end ;
    做了个触发器 ,,哎搞了半天没搞定,,出现下面错误
      3/23     PLS-00103: 出现符号 ""在需要下列之一时:   begin function package pragma     procedure subtype type use <an identifier>     <a double-quoted delimited-identifier> form current cursor  
     
      

  3.   

     进货单主表( MSK_Id 进货单编号(主键)   MMG_Id 保管员编号(外键)   MSE_Id  供应商编号(外键)  SK_InPutTime  入库时间     SK_Buyer  采购员 )
      
     进货单从表  ( SK_Id 编号 (自动递增)  SMSK_Id  进货单编号(外键) SGD_Id  商品编号(外键) SK_Num 入库数量)
    帐表 (CGD_Id 商品编号    CT_Year 年   CT_Month 月  CT_PreNum  起初数量  CT_InPutNum 入库数量   CT_FinalNum 期末数量 )
    这是三张表 
      

  4.   

    where CT_Year='v_year' and CT_Month='v_month' and CGD_Id='spbh'; 后面这些变量没有必要用'',这样反而出错了,它们本身就是有意义的变量,加上''后就变成字符串了。前面有个地方也是,其他地方没看