theory
theory

Reputation: 9887

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

I can run this command on Oracle 10.2 without problem:

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?

Upvotes: 4

Views: 22448

Answers (1)

A.B.Cade
A.B.Cade

Reputation: 16915

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;
/

Here is a fiddle

Upvotes: 2

Related Questions