日期:2014-05-17  浏览次数:20877 次

关于oracle存储过程
create or replace procedure proc_autoWarn as

 var_count number; --查询数目

 var_time date; --查询条件
 var_cname varchar(20); --中文名称

Cursor cur_cursor is select t.warn_obj,t.gather_fre,t.gather_set,t.log_num,t.warn_mode,t.mess_incepter,t.mess_no from t_warn_condition t;
begin
  

--循环执行
  for item in cur_cursor LOOP
  begin

  --配置条件
  if item.gather_fre=0 
  then
  var_time:=trunc(sysdate,'month');
  else if item.gather_fre=1
  then
  var_time:=trunc(sysdate);
  else
  var_time:=sysdate-item.gather_set/60/24;
  end if;

  --执行条件查询
  execute immediate 'select count(1) from '|| item.warn_obj ||' m where m.update_Time >'|| var_time into var_count ;
  execute immediate 'select m.remark from t_dict_info m where m.dict_code=warn_object and m.dict_value ='||item.warn_obj into var_cname ;
   
  --如果大于记录数,保存至日志表 t_warn_log
  if var_count > item.log_num then
  insert into t_warn_log
  (log_id,
  warn_date,
  c_warn_obj,
  e_warn_obj,
  warn_info,
  info_detail,
  note_date,
  flag)
  values
  (seq_warn_log_id.nextval,sysdate,var_cname,item.warn_obj,'成功',item.warn_obj||'成功',sysdate,1);
  --如果小于最小记录数,保存至日志表 t_warn_log 和发布表 t_warn_publish
  else
  insert into t_warn_log
  (log_id,
  warn_date,
  c_warn_obj,
  e_warn_obj,
  warn_info,
  info_detail,
  note_date,
  flag)
  values
  (seq_warn_log_id.nextval,sysdate,var_cname,item.warn_obj,'缺少数据或无数据',item.warn_obj||'缺少数据或无数据(数目少于'||var_count,sysdate,0);
   
  insert into t_warn_publish
  (publish_id, 
  warn_date, 
  c_warn_obj, 
  e_warn_obj, 
  warn_info, 
  info_detail, 
  publish_type, 
  incepter, 
  incepter_tel)
  values
  (seq_publish_id.nextval,sysdate,var_cname,item.warn_obj,'缺少数据或无数据',item.warn_obj||'缺少数据或无数据(数目少于'||var_count,item.warn_mode,item.mess_incepter,item.mess_no);
  commit;
  end if;
  end; --出错行

end loop;
end;


错误:
72 PLS:出现符号";"在需要下一列之一时:if

------解决方案--------------------
else if item.gather_fre=1 这里错了
改为elsif item.gather_fre=1就行了
------解决方案--------------------
else if 改成elsif