已知存在表job, job具有下述属性:
job_id : 岗位编号
titile: 岗位名称 如:系统分析师
min_salary: 此岗位最低工资
max_salary: 此岗位最高工资要求,编写一存储过程, 更新某一岗位的最高工资,如果更新后的最高工资低于最低工资,产生一个异常,向屏幕显示相应的错误信息。我的程序如下
set serveroutput on 
create or replace procedure update_job(new_max in job.max_salary%type,
new_id in job.job_id%type)
iscursor c1 is select job_id,min_salary,max_salary from job  for update;
invalid_input exception;begin if(not c1%isopen) then 
 open c1;
end if;
for c1_record in c1 loop
   if(c1_record.job_id=new_id)then
         dbms_output.put_line('Find it');
           update job set max_salary=new_max 
              where current of c1;
           dbms_output.put_line('Update it');
           if(c1_record.min_salary>c1_record.max_salary)then
               raise invalid_input;
           endif;
   endif;
end loop;
close c1;
exception
  when invalid_input then
   dbms_output.put_line('Max salary is less than Min!');end;
/ 但总是报错
encountered the symbol "end-of-file"when expecting one of the following : end not pragma final instantiable order overriding static member constructor map和
encountered the symbol "loop" when expecting one of the following : if
我想问的是for loop 中是不是不准使用if 或是别的类似的语句阿,我查一下好像没有在for loop 中使用if 的例子。

解决方案 »

  1.   

    FOR循环可以用条件语句。
    你后面两个“end if”写成“endif”,没空格。过程中的:
    if(not   c1%isopen)   then  
      open   c1;
    end   if; 
    和:close   c1; 
    都可以删掉,游标与for结合不用显式打开语句。而且你这个过程逻辑也不对,update过后才去判断值大小,if(c1_record.min_salary> c1_record.max_salary)条件也不对。
      

  2.   

    多谢这位大哥,我一直以为end if 与endif 一样来者。至于逻辑的问题,那得用trigger来调节吧 ,我重现调试了一下,已基本符合要求,现在我再加个trigger就ok了,主要是刚开始接触,出现语法错误不知咋办了,多谢大哥了。