【问题标题】:stored procedure in oracle 11goracle 11g 中的存储过程
【发布时间】:2017-05-08 16:59:53
【问题描述】:
create procedure p5(age1 IN number) as
     BEGIN
     if age1>18 then 
         insert into t values ( age1 );
     else
         dbms_output.putline('age should be high');
     end if;
end p5;

警告:过程创建时出现编译错误。

我已尝试执行此操作,但出现以下错误

SQL> exec p5(20);
BEGIN p5(20); END;
     *
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00905: object SYSTEM.P5 is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

我仍然收到这些错误

【问题讨论】:

  • 似乎您正在运行指向错误架构的测试。你是在 SYSTEM 中创建 p3 吗?你也用end p2关闭它...你的程序正在编译吗?
  • 我已将 p2 更改为 p3 并在第一行关闭括号
  • 使用show errors查看“编译错误”的详细信息

标签: sql oracle stored-procedures plsql


【解决方案1】:

有多个问题,

create or replace procedure p3(age1 IN number) as --you dont need (3) here. Also closing braces are missing.
     BEGIN
     if age1>18 then 
         insert into t values ( age1 );
     else
         dbms_output.put_line('age should be high'); --you were using putline.
     end if;
end p3;  --your proc name is p2 but you are endin p3. Not needed. Just END will also do.

我尝试在本地运行它,它工作正常。

create table t (age number(3));

表 T 已创建。

create procedure p3(age1 IN number) as 
 BEGIN
 if age1>18 then 
     insert into t values ( age1 );
 else
     dbms_output.put_line('age should be high');
 end if;
end p3;

程序 P3 编译

set serveroutput on;

exec p3(23);

PL/SQL 过程成功完成。

exec p3(17);

PL/SQL 过程成功完成。

年龄应该很高

select * from t;

AGE
23

【讨论】:

  • SQL> create procedure p4(age1 IN number(3)) as 2 BEGIN 3 if age1>18 then 4 insert into t values ( age1 ); 5 else 6 dbms_output.putline('年龄应该很高'); 7 结束如果; 8结束p4; 9 / 警告:创建的过程存在编译错误。 SQL> 执行 p4(20);开始 p4(20);结尾; * 第 1 行出现错误:ORA-06550:第 1 行,第 7 列:PLS-00905:对象 SYSTEM.P4 无效 ORA-06550:第 1 行,第 7 列:PL/SQL:语句被忽略,我仍然收到这些错误跨度>
  • 您使用的是putline。使用put_line。更新了答案。
  • @nagesh 请编辑您的问题添加您收到的更改和额外消息
  • @nagesh - 你没有阅读我的答案。我告诉过你不需要number (3) ,只需使用number。那你为什么又用它?
  • 另外,如果您想重用名称,请使用create or replace procedure..
【解决方案2】:

错误在这里:

dbms_output.put_line

而不是

dbms_output.putline

【讨论】:

    【解决方案3】:

    您在 p3(age1 IN number(3) 之后错过了右括号。请尝试以下操作:

    create procedure p3(age1 IN number) as
         BEGIN
         if age1>18 then 
             insert into t values ( age1 );
         else
             dbms_output.put_line('age should be high');  -- it should be put_line
         end if;
    end p3;  --correct procedure name
    

    【讨论】:

    • @nagesh 立即尝试
    • 我的表名有误。它现在可以工作了,谢谢大家
    猜你喜欢
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-13
    • 2014-05-07
    • 2020-06-15
    • 1970-01-01
    相关资源
    最近更新 更多