oracel语句增加判断

来源:互联网 发布:丐姐捏脸数据 编辑:程序博客网 时间:2024/06/06 02:46

/*字典表增加故障服务项.sql*/
declare
  v_cnt1 number;v_cnt2 number;
  v_cnt3 number;v_cnt4 number;

begin

--先查询是否有这些数据

  select count(*) into v_cnt1 from ak_publiccode where id =1050;
  select count(*) into v_cnt2 from ak_publiccode where id =1051;
  select count(*) into v_cnt3 from ak_publiccode where id =1052;
  select count(*) into v_cnt4 from ak_publiccode where id =1053;

  if v_cnt1 = 0 then

--如果没有则插入数据

   insert into ak_publiccode values(1050,'故障',null,'事件类型',null,0,0);
  end if;
  if v_cnt2 = 0 then
   insert into ak_publiccode values(1051,'服务',null,'事件类型',null,0,0);
  end if;
  if v_cnt3 = 0 then
  insert into ak_publiccode values(1052,'客户服务器重启',1051,'事件类型',null,0,0);
  end if;
  if v_cnt4 = 0 then
 insert into ak_publiccode values(1053,'查看设备状态',1051,'事件类型',null,0,0);
  end if;
end;