带有alter语句的ORA-06550

时间:2019-05-30 00:54:57

标签: oracle plsql

我正在尝试使用此代码进行某些测试,但出现此错误ORA-06550

我试图用set修改列,但许多结果仍然相同

代码:

declare

cursor cur is select  comm from emp where comm is not null ;

enreg emp.comm%type;

moyene number;

somme number;

begin

open cur;
loop

fetch cur into enreg;

if emp.comm=enreg.com then

ALTER TABLE emp 

set columun 

emp.comm := enreg.com*100/emp.comm ;  

end if ;

exit when cur%notfound;

end loop;

end;

预期结果是将每个emp.comm更改为10%,但我收到了此错误

错误:

ORA-06550: line 12, column 1:
PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:

   ( begin case declare exit for goto if loop mod null pragma
   raise return select update while with 
     <<
   continue close current delete fetch lock insert open rollback
   savepoint set sql execute commit forall merge pipe purge

1. declare
2. cursor cur is select  comm from emp where comm is not null ;
3. enreg emp.comm%type;

1 个答案:

答案 0 :(得分:1)

在SQL中,您使用UPDATE语句来更改表中的值。 ALTER TABLE用于更改表的结构,例如通过添加列等。您可以按以下方式重写代码:

declare
  cursor cur is select  comm from emp where comm is not null;
  enreg   emp.comm%type;  
  moyene  number;
  somme   number;  
begin    
  open cur;

  loop  
    fetch cur into enreg;
    exit when cur%notfound;

    if emp.comm = enreg then
      update emp 
         set emp.comm = enreg * 100 / emp.comm;  
    end if ;
  end loop;

  commit;
end;

好运。