2013-03-13 51 views
1

我创建了一个名为过程迎接为:为什么我在尝试调用过程时遇到错误?

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

@EgorSkriptunoff属性的值是'ERROR'!但是早些时候它给出了编译成功的信息: –

+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的空白填充语义的情况是非常罕见的。

+0

char(50)'有什么问题?为什么会产生错误? –

+1

@SuhailGupta - 正如我所说的,你不能为输入参数指定一个长度。您可以像我在示例中那样指定数据类型(本例中为“CHAR”)。长度将基于实际传入的参数的长度。 –

1

这是工作伙计;

create or replace 
procedure greet(message in char) 
as 
begin 
    dbms_output.put_line('Greet Message : ' || message); 
end; 

看到char数据类型的主要属性是输入数据的长度小于指定它会添加空格。这情况下,不发生对VARCHAR2的大小。

  1. 在上述字符属性过程违反所以它几乎像对待VARCHAR2。所以如果你删除输入参数的大小它将工作,也支持字符输入的最大长度。
相关问题