oracle 是什么导致了这个 PL/SQL 函数中的数值溢出?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12829231/
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:10:18  来源:igfitidea点击:

What Causes the Numeric Overflow in this PL/SQL Function?

oracleplsqloverflownumeric

提问by theory

I can run this command on Oracle 10.2 without problem:

我可以在 Oracle 10.2 上毫无问题地运行此命令:

SQL> select instr(unistr('foo'), chr(4050596145)) as hazit from dual;

     HAZIT
----------
     0

So I tried to encapsulate it into a function:

于是我试着把它封装成一个函数:

CREATE OR REPLACE FUNCTION hazit(string IN VARCHAR2) RETURN INTEGER
AS
BEGIN
    RETURN instr(unistr(string), chr(4050596145));
END;
/

Function created.

But I get a numeric overflow error when I try to use it:

但是当我尝试使用它时出现数字溢出错误:

SQL> select hazit('foo') FROM DUAL;
select hazit('foo') FROM DUAL
       *
ERROR at line 1:
ORA-01426: numeric overflow
ORA-06512: at "DWHEELER.HAZIT", line 4

What gives?

是什么赋予了?

采纳答案by A.B.Cade

I don't have an explanation but this seems to work:

我没有解释,但这似乎有效:

CREATE OR REPLACE FUNCTION hazit(string IN VARCHAR2) RETURN NUMBER IS
i number;
BEGIN
    select instr(unistr(string), chr(4050596145))
      into i from dual;
    return i;
END;
/

Hereis a fiddle

是一个小提琴