我创建了一个名为 greet 的过程:
create procedure greet(message in char(50))
as
begin
dbms_output.put_line('Greet Message : ' || message);
end;
程序编译成功,但当我尝试将其称为:
execute greet('Hey ! This is a self created procedure :)');
我收到错误:
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:
它有什么错误?我为什么要这样做?
注意:'suhail'是连接到oracle服务器的当前用户的名称
答案 0 :(得分:6)
我不相信您的程序编译成功。当我尝试在我的系统上编译它时,我得到语法错误
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.
如果我解决语法错误(你不能指定输入参数的长度),它可以正常工作
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.
如果您真的希望将输入参数声明为CHAR
,我会感到震惊。几乎总是,您应该使用VARCHAR2
作为字符串。在您真正需要CHAR
的空白填充语义的情况下,非常罕见。
答案 1 :(得分:1)
这是工作的老兄;
create or replace
procedure greet(message in char)
as
begin
dbms_output.put_line('Greet Message : ' || message);
end;
请参阅char数据类型的主要属性是输入数据的长度小于您指定的大小它将添加空格。这种情况不会发生在varchar2上。