PL/SQL 中的函数错误

发布于 2024-12-22 00:29:32 字数 750 浏览 1 评论 0原文

我尝试创建以下函数:

CREATE OR REPLACE
function CATEGORYTEST(n in number) return VARCHAR(200)
IS
  catname VARCHAR(200);
  BEGIN
  SELECT NAME AS PARENTCAT INTO CATNAME FROM CATEGORY_LANGUAGE WHERE CATEGORY_ID = (
      SELECT PARENT_ID
      FROM CATEGORY
      WHERE ID        = N
      AND CAT_TYPE_ID = 7
      AND IS_ACTIVE   = 1
      AND IS_DELETED  = 0
      )
      AND IS_ACTIVE = 1
      AND IS_DELETED = 0;
   RETURN CATNAME;   
end;

我收到以下错误:

Error(2,51): PLS-00103: Encountered the symbol "(" when expecting one of the following:     . @ % ; is authid as cluster order using external character    deterministic parallel_enable pipelined aggregate 

我也尝试过 varchar2 但收到相同的错误。

I tried to create following function:

CREATE OR REPLACE
function CATEGORYTEST(n in number) return VARCHAR(200)
IS
  catname VARCHAR(200);
  BEGIN
  SELECT NAME AS PARENTCAT INTO CATNAME FROM CATEGORY_LANGUAGE WHERE CATEGORY_ID = (
      SELECT PARENT_ID
      FROM CATEGORY
      WHERE ID        = N
      AND CAT_TYPE_ID = 7
      AND IS_ACTIVE   = 1
      AND IS_DELETED  = 0
      )
      AND IS_ACTIVE = 1
      AND IS_DELETED = 0;
   RETURN CATNAME;   
end;

I am getting following error:

Error(2,51): PLS-00103: Encountered the symbol "(" when expecting one of the following:     . @ % ; is authid as cluster order using external character    deterministic parallel_enable pipelined aggregate 

I had tried varchar2 also but getting same error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枉心 2024-12-29 00:29:32

试试这个:

CREATE OR REPLACE 
FUNCTION CATEGORYTEST(
   n IN NUMBER
) 
   RETURN VARCHAR2
IS
   catname VARCHAR2(200);
BEGIN
   SELECT NAME AS PARENTCAT
     INTO CATNAME
     FROM CATEGORY_LANGUAGE
    WHERE CATEGORY_ID = (SELECT PARENT_ID
                           FROM CATEGORY
                          WHERE ID = 'N'
                            AND CAT_TYPE_ID = 7
                            AND IS_ACTIVE   = 1
                            AND IS_DELETED  = 0)
      AND IS_ACTIVE = 1
      AND IS_DELETED = 0;

    RETURN CATNAME;
end CATEGORYTEST; 

您需要将字符串文字用单引号括起来,将 VARCHAR 更改为 VARCHAR2 以及其他一些小的更改。

顺便说一句,您的 catname 变量最好声明为:

catname CATEGORY_LANGUAGE.NAME%TYPE;

您可能还想查看也被灵活声明的函数的返回类型,例如:

RETURN CATEGORY_LANGUAGE.NAME%TYPE

希望它有帮助......

Try this:

CREATE OR REPLACE 
FUNCTION CATEGORYTEST(
   n IN NUMBER
) 
   RETURN VARCHAR2
IS
   catname VARCHAR2(200);
BEGIN
   SELECT NAME AS PARENTCAT
     INTO CATNAME
     FROM CATEGORY_LANGUAGE
    WHERE CATEGORY_ID = (SELECT PARENT_ID
                           FROM CATEGORY
                          WHERE ID = 'N'
                            AND CAT_TYPE_ID = 7
                            AND IS_ACTIVE   = 1
                            AND IS_DELETED  = 0)
      AND IS_ACTIVE = 1
      AND IS_DELETED = 0;

    RETURN CATNAME;
end CATEGORYTEST; 

You needed single quotes around your string literals, VARCHAR changed to VARCHAR2 and some other small changes.

BTW, your catname variable would be better declared as:

catname CATEGORY_LANGUAGE.NAME%TYPE;

You might also want to look into the return type of the function also being flexibly declared e.g.:

RETURN CATEGORY_LANGUAGE.NAME%TYPE

Hope it helps...

满地尘埃落定 2024-12-29 00:29:32

使用此标头:(

CREATE OR REPLACE function CATEGORYTEST(n in number) return VARCHAR

返回类型没有长度规范)

Use this header:

CREATE OR REPLACE function CATEGORYTEST(n in number) return VARCHAR

(no length specification for the return type)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文