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

oracle中end if 于end 的区别
请大哥们帮我解答下
oracle中end if 于end 的区别
搞了一个晚上还是没搞好。不知道什么原因
代码如下:
declare
  up_record up%rowtype;
  user_reco userinfo%rowtype;
  text string(50):='手机用户';
  usernum int;
  cursor up_cus is select * from up;
  cursor user_cus is select * from userinfo;
  begin
  open up_cus;
  fetch up_cus into up_record;
  while up_cus%found
  loop
  if(up_record.content='G')then
  dbms_output.put_line(text||up_record.phonenum||'注册成功,请发送R到10086领题');
  insert into down values(test.sq_downid.nextval,up_record.phonenum,up_record.content,up_record.indate,up_record.opposite);
  delete up where upid=up_record.upid;
  end if;
  if(up_record.content='R')then
  select count(*) into usernum from userinfo where userinfo.phonenum=up_record.phonenum;
  dbms_output.put_line(usernum);
  end if;
  if(usernum>0)then
  begin
  dbms_output.put_line('成功领取题目,请回复F加答案到10086');
  else
  dbms_output.put_line(text||up_record.phonenum||'请先发送G到10086进行注册!');
  end if; 
  end;
  end if;
   
  fetch up_cus into up_record;
  end loop;
  close up_cus;
  end;

------解决方案--------------------
大哥,你吓我一跳。
出现一个if ,你就要一个end if;
end if 是指针对 if的;end 是针对begin的。
还有end case 是针对case的,当然end case 有些情况也可以省略case,略写:end;等等
------解决方案--------------------
if(usernum>0)then
begin
dbms_output.put_line('成功领取题目,请回复F加答案到10086');
else
dbms_output.put_line(text||up_record.phonenum||'请先发送G到10086进行注册!');
end if;
end;
end if; 

这段代码错了,begin ...end 用错了;这样即可
if (usernum > 0) then
dbms_output.put_line('成功领取题目,请回复F加答案到10086');
else
dbms_output.put_line(text || up_record.phonenum || '请先发送G到10086进行注册!');
end if;
如果要加begin...end ,就
if (usernum > 0) then
begin
dbms_output.put_line('成功领取题目,请回复F加答案到10086');
end;
else
begin
dbms_output.put_line(text || up_record.phonenum || '请先发送G到10086进行注册!');
end;
end if;

简单的说begin ...end就相当于 ( ) ;