这是源代码:create or replace package my_pack
is
  procedure UpdateProductPrice;
  function AvgProductPrice return number;
end;create or replace package body
    my_pack is
    procedure UpdateProductPrice
    is
      avp number;
    begin
         select AvgProductPrice() into avp from daul;
         loop
             exit when avp>40;
             update products set price:=60 where price>60;
             update products set price:=price+price*0.1;
             select AvgProductPrice() into avp from daul;
         end loop;
    end UpdateProductPrice;   function AvgProductPrice
    return number
    is
      pri number;
    begin
        select avg(price) into  pri from products;
        return pri;
    end AvgProductPrice;
end my_pack;

解决方案 »

  1.   


    create or replace package my_pack
    is
      procedure UpdateProductPrice;
      function AvgProductPrice return number;
    end;
    /create or replace package body
      my_pack is
      procedure UpdateProductPrice
      is
      avp number;
      begin
       execute immediate 'select AvgProductPrice() from daul'
    into avp;
      loop
      exit when avp>40;
      update products set price=60 where price>60;
      update products set price=price+price*0.1;
      execute immediate 'select AvgProductPrice() from daul'
    into avp;
      end loop;
      end UpdateProductPrice;  function AvgProductPrice
      return number
      is
      pri number;
      begin
      execute immediate 'select avg(price) from products'
    into pri;
      return pri;
      end AvgProductPrice;
    end my_pack;
    /
      

  2.   

    2错误
    1)set price:=60 把:去掉,这是对变量赋值的时候才需要的
    2)from daul拼写错误,应该是from dual.create or replace package body
      my_pack is
      procedure UpdateProductPrice
      is
      avp number;
      begin
      select AvgProductPrice() into avp from dual;
      loop
      exit when avp>40;
      update products set price=60 where price>60;
      update products set price=price+price*0.1;
      select AvgProductPrice() into avp from dual;
      end loop;
      end UpdateProductPrice;  function AvgProductPrice
      return number
      is
      pri number;
      begin
      select avg(price) into pri from products;
      return pri;
      end AvgProductPrice;
    end my_pack;