Oracle 函数 - VARCHAR2 长度错误 (PLS-00215)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18197822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:51:55  来源:igfitidea点击:

Oracle Functions - VARCHAR2 length error (PLS-00215)

oraclefunctionstored-procedures

提问by dbpullman

I've been messing around with this for about the last 2 hours, and can't seem to find anything helpful (I've read up on some solutions, but for me they aren't working). I have the following create function statement:

在过去的 2 个小时里,我一直在搞这个,似乎找不到任何有用的东西(我已经阅读了一些解决方案,但对我来说它们不起作用)。我有以下创建函数语句:

CREATE FUNCTION GetBatchApprovalEmail(net_id IN NUMBER)
  RETURN VARCHAR2
IS
  email_address VARCHAR2(255);

  CURSOR C1 IS
    SELECT T1.approve_email
      FROM LMS.LMS_STATUS_EMAIL T1
        WHERE T1.NET_ID = net_id
BEGIN

  OPEN C1;
  FETCH C1 into email_address;
  CLOSE C1;

  RETURN email_address;
END;
/

For some reason, upon executing this statement I get a

出于某种原因,在执行此语句时,我得到一个

PLS-00215 error (String length constraints must be in range(1 .. 32767)).

PLS-00215 error (String length constraints must be in range(1 .. 32767)).

I've been reading up and most have said to just declare a size for the VARCHAR2, but I've tried and it doesn't make a difference.

我一直在阅读,大多数人都说只为 声明一个大小VARCHAR2,但我已经尝试过并且没有任何区别。

Does anyone have any ideas? PS I'm fairly new to PL/SQLso its possible other things aren't correct.

有没有人有任何想法?PS 我PL/SQL对它还很陌生,所以其他可能的事情是不正确的。

回答by XING

There are few errors to your function. Check below to understand those.

您的函数几乎没有错误。检查以下以了解这些。

CREATE FUNCTION GetBatchApprovalEmail(net_id IN NUMBER)
  RETURN VARCHAR2
IS
  email_address VARCHAR2(255);

  CURSOR C1(num number) IS           ---Using passed parameter to the cursor
    SELECT T1.approve_email
      FROM LMS.LMS_STATUS_EMAIL T1
        WHERE T1.NET_ID = num;  
BEGIN

  OPEN C1(net_id);   --- This is the ways to pass parameter to a cursor.

  FETCH C1 into email_address;

  CLOSE C1;

  RETURN email_address;
END;