0

为什么它不起作用?我在 oracle 中运行它。我想创建这样的程序:

CREATE OR REPLACE PROCEDURE ME( X in NUMBER )IS  
declare 
num1 number;
BEGIN  
num1:=1;
insert into a (year) values(7);    
END; 

这是错误:

PLS-00103:在预期以下情况之一时遇到符号“DECLARE”:开始函数杂注过程子类型类型当前游标删除存在先前的外部语言符号“开始”替换“声明”以继续。7/5 PLS-00103:在预期以下情况之一时遇到符号“文件结尾”:(开始案例声明结束异常退出 goto if loop mod null pragma raise return select update while with << continue close current delete获取锁插入打开回滚保存点设置sql执行提交forall合并管道清除

4

2 回答 2

5

DECLARE is only used in anonymous PL/SQL blocks and nested PL/SQL blocks. You wouldn't use it when you're declaring a procedure. Assuming the table A exists with a column YEAR, something like

CREATE OR REPLACE PROCEDURE ME( X in NUMBER )
IS  
  num1 number;
BEGIN  
  num1:=1;
  insert into a (year) values(7);    
END; 

is syntactically valid. Of course, there are all sorts of issues with the code... You take a parameter that you don't use, you declare a local variable that you don't use, the name of the procedure has no relation to what the procedure does, etc.

于 2013-05-30T07:20:08.283 回答
1

试试看

    CREATE OR REPLACE PROCEDURE me (x IN NUMBER)
IS
    num1     NUMBER;
BEGIN
    num1 := 1;    
    insert into a (year) values(7);     
END;
/
于 2013-05-30T07:22:15.667 回答