日期:2014-05-16  浏览次数:20411 次

关于 票数统计 1张主表 含有各个计票项 1张子表 含有各个用户选择项
源:
评:
主表  haier2013_datatoupiao
子表  haier2013_data board_id = 15的为 用户投票内容信息



create or replace trigger HAIER_TOUPIAO_BOARD_ID_15_17
  after insert on haier2013_data 
  for each row

declare
  -- local variables here
  lpos1 number :=1;
  lpos2 number :=1;
  lbuff varchar2(50) :='';
begin
  if :new.board_id = 15 then
    while lpos1 <= length(:new.remark1) loop
      lpos2 :=instr(:new.remark1, ';', lpos1, 1);
      if lpos2 = 0 then
        lbuff := substr(:new.remark1,lpos1, 1);
        update haier2013_datatoupiao t set t.con_type= t.con_type+1 where t.board_id = 17 and t.name = lbuff;
        exit;
      end if;
     
      lbuff:=substr(:new.remark1, lpos1, 1);
      update haier2013_datatoupiao t set t.con_type= t.con_type+1 where t.board_id = 17 and t.name = lbuff;
     
      lpos1 := lpos2 + 1;
    end loop;
  end if;

end HAIER_TOUPIAO_BOARD_ID_15_17;