Oracle 带alter语句的ORA-06550

Oracle 带alter语句的ORA-06550,oracle,plsql,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.co

我正在尝试这个代码进行一些测试,我得到了这个错误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;
ORA-06550:第12行第1列:
PLS-00103:在预期以下情况时遇到符号“ALTER”:
(begin case如果循环mod null pragma,则为goto声明退出
使用时升高返回选择更新

在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;

祝你好运。

要更改列中的值,必须使用not ALTER(它更改表的结构,而不是值)。但是整个过程和循环都是完全无用的。这可以通过一个没有循环或PL/SQL的简单UPDATE语句来完成。如果您真的想以如此低效和缓慢的方式来完成,请使用UPDATE和
,其中CURRENT OF
来更改游标的“当前行”
ALTER
修改表定义(列名、数据类型等),而不是数据本身。
UPDATE
更新列值。一个好的SQL教程似乎对您有所帮助。