create procedure关键字不起作用

时间:2012-01-09 15:52:17

标签: plsql oracle11g

如果我编写程序创建这样的代码

declare
salary   number :=20000;
employee_id  number :=36325;
   procedure give_bonus(emp_id in number,bonus in number)  is
begin
dbms_output.put_line(emp_id);
dbms_output.put_line(bonus);
end;
 begin
 case
 when salary >=10000 and salary <=20000 then
 give_bonus(employee_id,1500);
 when  salary >= 20000 and salary <=40000 then
 give_bonus(employee_id,1000);
 when  salary>40000 then
 give_bonus(employee_id,500);
 else
 give_bonus(employee_id,0);
 end case ;
 end;

 it writes on output  
anonymous block completed

但是如果我写一个程序主管这一个 创建或替换程序give_bonus,它写错误,请帮帮我为什么? 错误是这个

在命令的第1行开始出错:

declare
salary   number :=20000;
employee_id  number :=36325;
  create or replace  procedure give_bonus(emp_id in number,bonus in number)  is
begin
dbms_output.put_line(emp_id);
dbms_output.put_line(bonus);
end;
 begin
 case
 when salary >=10000 and salary <=20000 then
 give_bonus(employee_id,1500);
 when  salary >= 20000 and salary <=40000 then
 give_bonus(employee_id,1000);
 when  salary>40000 then
 give_bonus(employee_id,500);
 else
 give_bonus(employee_id,0);
 end case ;
 end;




Error report:
ORA-06550: line 4, column 3:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:

   begin function pragma procedure subtype type <an identifier>
   <a double-quoted delimited-identifier> current cursor delete
   exists prior
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

1 个答案:

答案 0 :(得分:2)

CREATE OR REPLACE仅适用于顶级对象。如果要在另一个PL / SQL块中声明一个过程,根据定义,没有什么可以替换的。一旦匿名块完成,您就不会创建一个存在的过程,因此无需替换任何内容。您只是声明一个与局部变量具有相同范围的过程。

您可以创建独立程序

create or replace  procedure give_bonus(emp_id in number,bonus in number)  
is
begin
  dbms_output.put_line(emp_id);
  dbms_output.put_line(bonus);
end;

然后在您的匿名PL / SQL块中引用该过程

declare
  salary   number :=20000;
  employee_id  number :=36325;
begin
  case
  when salary >=10000 and salary <=20000 then
    give_bonus(employee_id,1500);
   when  salary >= 20000 and salary <=40000 then
     give_bonus(employee_id,1000);
   when  salary>40000 then
     give_bonus(employee_id,500);
   else
     give_bonus(employee_id,0);
  end case ;
end;