CREATE or replace FUNCTION f
return integer
AS;
BEGIN
return (select count(*) from exemplo);
END ;
select f() from dual;
当我执行功能时,请给我这个错误:
ORA-06575: Package or function F is in an invalid state
答案 0 :(得分:3)
编译函数时,客户端会说:
Warning: Function created with compilation errors.
或
Function F compiled
Errors: check compiler log
如果您正在使用SQL * Plus或SQL Developer(可能还有其他客户端,但它们可能有自己的等效客户端),那么您可以show errors
查看错误:
LINE/COL ERROR
-------- -----------------------------------------------------------------
3/3 PLS-00103: Encountered the symbol ";" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior external language
或者您可以查询user_errors
视图以查看相同的信息。
在AS
之后删除分号,然后报告:
LINE/COL ERROR
-------- -----------------------------------------------------------------
5/11 PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternat
5/39 PLS-00103: Encountered the symbol ")" when expecting one of the following:
. , @ ; for <an identifier>
<a double-quoted delimited-identifier> group having intersect
minus order partition start subpartition union where connect
sample
您无法直接返回查询结果。您需要一个局部变量来选择到,然后返回;类似的东西:
CREATE or replace FUNCTION f
return integer
AS
l_count pls_integer;
BEGIN
select count(*) into l_count from exemplo;
return l_count;
END ;
/
答案 1 :(得分:1)
运行alter session set nls_language = 'English';
以获取英文错误消息。
功能必须如下:
CREATE or replace FUNCTION f return integer AS
ret INTEGER;
BEGIN
select count(*) INTO ret from exemplo;
return ret;
END;