Oracle PL-SQL 函数出现错误 PLS-00103:遇到以下符号之一时遇到符号 "SELECT"
Oracle PL-SQL function getting error PLS-00103: Encountered the symbol "SELECT" when expecting one of the following
create or replace function noMembers(projNum integer) return integer IS
memCount integer;
Begin
memCount := ( select count(*)
from TABLE( select p.members from Projects p where p.projNo = projNum));
return memCount;
End;
End;
当我尝试在 Oracle 中创建上述函数时 - SQL*另外,我得到了错误;
LINE/COL ERROR
-------- -----------------------------------------------------------------
3/10 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
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/69 PLS-00103: Encountered the symbol ")" when expecting one of the
following:
, ; for <an identifier>
<a double-quoted delimited-identifier> as group having
intersect minus order start union where connect
似乎找不到函数声明有什么问题,我想return从函数分配给每个项目的成员数(成员计数)。
select count(*) from TABLE( select p.members from Projects p where p.projNo = 10 )
以上查询单独执行时效果很好。我还需要在函数中声明的“memCount
”变量。
感谢任何帮助...
你不能这样分配查询结果;语法是:
select count(*)
into memCount
from ...
But is it possible to assign to the memCount variable by any chance ( I mean using ' := ' operator ) ?
Not directly from a query。您可以将整个集合查询到一个局部变量中,然后您可以分配它的计数:
create or replace function noMembers(projNum integer) return integer IS
memCount integer;
memColl projects.members%type;
Begin
select p.members
into memColl
from Projects p where p.projNo = projNum;
memCount := memColl.count;
return memCount;
End;
/
或没有分配:
create or replace function noMembers(projNum integer) return integer IS
memColl projects.members%type;
Begin
select p.members
into memColl
from Projects p where p.projNo = projNum;
return memColl.count;
End;
/
但除非您打算对集合做任何其他事情,否则这可能只是浪费精力和内存。
create or replace function noMembers(projNum integer) return integer IS
memCount integer;
Begin
memCount := ( select count(*)
from TABLE( select p.members from Projects p where p.projNo = projNum));
return memCount;
End;
End;
当我尝试在 Oracle 中创建上述函数时 - SQL*另外,我得到了错误;
LINE/COL ERROR
-------- -----------------------------------------------------------------
3/10 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
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/69 PLS-00103: Encountered the symbol ")" when expecting one of the
following:
, ; for <an identifier>
<a double-quoted delimited-identifier> as group having
intersect minus order start union where connect
似乎找不到函数声明有什么问题,我想return从函数分配给每个项目的成员数(成员计数)。
select count(*) from TABLE( select p.members from Projects p where p.projNo = 10 )
以上查询单独执行时效果很好。我还需要在函数中声明的“memCount
”变量。
感谢任何帮助...
你不能这样分配查询结果;语法是:
select count(*)
into memCount
from ...
But is it possible to assign to the memCount variable by any chance ( I mean using ' := ' operator ) ?
Not directly from a query。您可以将整个集合查询到一个局部变量中,然后您可以分配它的计数:
create or replace function noMembers(projNum integer) return integer IS
memCount integer;
memColl projects.members%type;
Begin
select p.members
into memColl
from Projects p where p.projNo = projNum;
memCount := memColl.count;
return memCount;
End;
/
或没有分配:
create or replace function noMembers(projNum integer) return integer IS
memColl projects.members%type;
Begin
select p.members
into memColl
from Projects p where p.projNo = projNum;
return memColl.count;
End;
/
但除非您打算对集合做任何其他事情,否则这可能只是浪费精力和内存。