oracle 为什么在尝试调用过程时会出现错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15381052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why do I get an error as I try to call a procedure?
提问by Suhail Gupta
I created a procedure named greetas :
我创建了一个名为greet的过程:
create procedure greet(message in char(50))
as
begin
dbms_output.put_line('Greet Message : ' || message);
end;
The procedure compiled successfully but when I try to call it as :
该过程编译成功,但是当我尝试将其称为:
execute greet('Hey ! This is a self created procedure :)');
I get an error :
我收到一个错误:
execute greet('Hey ! This is a self created procedure :)')
Error report:
ORA-06550: line 1, column 7:
PLS-00905: object SUHAIL.GREET is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
What error is it ? Why do I get it ?
这是什么错误?为什么我会得到它?
Note : 'suhail' is name of the current user connected to oracle server
注意:'suhail' 是当前连接到 oracle 服务器的用户名
回答by Justin Cave
I don't believe that your procedure compiled successfully. When I try to compile it on my system, I get syntax errors
我不相信你的程序编译成功。当我尝试在我的系统上编译它时,出现语法错误
SQL> create procedure greet(message in char(50))
2 as
3 begin
4 dbms_output.put_line('Greet Message : ' || message);
5 end;
6 /
Warning: Procedure created with compilation errors.
SQL> sho err
Errors for PROCEDURE GREET:
LINE/COL ERROR
-------- -----------------------------------------------------------------
1/32 PLS-00103: Encountered the symbol "(" when expecting one of the
following:
:= ) , default varying character large
The symbol ":=" was substituted for "(" to continue.
If I resolve the syntax errors (you cannot specify a length for an input parameter), it works
如果我解决了语法错误(您不能为输入参数指定长度),它就可以工作
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure greet(message in char)
2 as
3 begin
4 dbms_output.put_line('Greet Message : ' || message);
5* end;
SQL> /
Procedure created.
SQL> set serveroutput on;
SQL> execute greet('Hey ! This is a self created procedure :)');
Greet Message : Hey ! This is a self created procedure :)
PL/SQL procedure successfully completed.
I would be shocked if you really wanted the input parameter to be declared as CHAR
. Almost always, you should use VARCHAR2
for character strings. It is exceptionally rare to come across a case where you really want the blank-padding semantics of a CHAR
.
如果您真的希望将输入参数声明为CHAR
. 几乎总是,您应该使用VARCHAR2
for 字符串。遇到您真正想要CHAR
.
回答by Thiyagu ATR
this is working dude;
这是工作的家伙;
create or replace
procedure greet(message in char)
as
begin
dbms_output.put_line('Greet Message : ' || message);
end;
see main property of char datatype is is the length of input data is less than the size you specified it'll add blank spaces.this case is not happened for varchar2.
请参阅 char 数据类型的主要属性是输入数据的长度小于您指定的大小,它将添加空格。varchar2 不会发生这种情况。
- in procedure above mentioned char property is violated so it's almost treat like varchar2. so if you remove size of input parameterit will work and also char support maximum length of input.
- 在上述过程中,违反了 char 属性,因此它几乎像 varchar2 一样对待。因此,如果您删除输入参数的大小,它将起作用,并且字符支持最大输入长度。