[英]Substr with more than 4000 characters gets ORA-06502: PL/SQL: numeric or value error
In the below script if I try to substr for 4000 character it works and displays all text in my particular ID with respective DB field ID and Language, if I increase it even 4001 db pops up the error - ora-06502: pl/sql: numeric or value error. 在下面的脚本中,如果我尝试用4000字符代替,那么它将起作用并显示我的特定ID中的所有文本以及相应的DB字段ID和语言,如果增加它,甚至4001 db也会弹出错误-ora-06502:pl / sql:数字或值错误。
Create or replace function GET_AER_TEXT5(M_AER_ID IN NUMBER,
F_ID IN VARCHAR2,PREF_LANGUAGE IN VARCHAR2)
IS
AERTEXT VARCHAR2(32000);
LANG_PARAM VARCHAR2(2000);
AER_CLOB CLOB;
BEGIN
FOR c1 IN (
select TEXT from AER_TEXT
where FIELD_ID=F_ID and AER_ID=M_AER_ID and LANGUAGE IN(PREF_LANGUAGE)
)
LOOP
IF c1.text IS NOT NULL THEN
AER_CLOB:=AER_CLOB || c1.text;
END IF;
END LOOP;
AERTEXT:=substr(AER_CLOB,1,4000);
RETURN(AERTEXT);
END;
Importance of increasing this to more than 4000 is to pull complete text data. 将其增加到4000多个的重要性是提取完整的文本数据。 If the DB column contains more than 4K character it doesn't work.
如果数据库列包含的字符超过4K,则该行不起作用。
I'm calling it with: 我这样称呼:
select AER_ID,GET_AER_TEXT5(AER_ID,at,field_id,'001')
from AER a,AER_TEXT AT
where AT.field_ID=12345 and a.aer_id=at.aer_id;
Can you please advise how to get rid of this issue. 您能建议如何摆脱这个问题吗?
Prior to Oracle 12c Oracle only allows 4000 bytes in a varchar2 value in an SQL context. 在Oracle 12c之前,Oracle在SQL上下文中的varchar2值中仅允许4000字节。 You are allowed 32k in PL/SQL, so your function is sort of OK as it stands, even with the substrng getting the first 4001 characters;
在PL / SQL中允许使用32k,因此即使substrng获得前4001个字符,您的功能也可以正常使用。 but only if you call it from PL/SQL.
但仅当您从PL / SQL调用它时。 When you try to call it from SQL:
当您尝试从SQL调用它时:
select AER_ID,GET_AER_TEXT5(AER_ID,at,field_id,'001') ...
... you're trying to assign a 4001-character value to the implicit SQL column in the return statement, and that is causing the error you are seeing. ...您正在尝试将4001个字符的值分配给return语句中的隐式SQL列,这将导致您看到的错误。
You can either change your SAP call to use a PL/SQL context and a bind variable to get the return value, though you'll still be limited to 32k; 您可以将SAP调用更改为使用PL / SQL上下文,并可以使用绑定变量来获取返回值,尽管仍然限于32k。 or change your function to keep value as a CLOB, which makes the function a bit pointless as you can just get the value from the table.
或更改您的函数以将值保留为CLOB,这使函数有点毫无意义,因为您可以从表中获取值。 I'm not familiar with SAP so I'm not quite sure how you'd end up coding either approach.
我对SAP不熟悉,所以我不太确定您最终将如何编码这两种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.