Home » SQL & PL/SQL » SQL & PL/SQL » how to identify only a non numeric data
how to identify only a non numeric data [message #39019] Fri, 07 June 2002 00:21 Go to next message
Samir
Messages: 32
Registered: April 2002
Member
Hello,
There one know a function to identify a numeric:
explication:
i have data such:
12344
56344
8dfdd5
9phgh1
......

i want to select only data who is not a numeric or a numeric is.
Thus i ask if oracle contains a functon to do that?

Tanks
Re: how to identify only a non numeric data [message #39021 is a reply to message #39019] Fri, 07 June 2002 03:16 Go to previous messageGo to next message
Rick Cale
Messages: 111
Registered: February 2002
Senior Member
Oracle does not have such a function but it
would be easy enough to create one.

Just do a SELECT TO_NUMBER(v_string) FROM dual;
Trap the ora-1722 error. If you get the error you know
it is non-numeric else it is numeric.

Rick
Re: how to identify only a non numeric data [message #39027 is a reply to message #39019] Fri, 07 June 2002 07:34 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
is this helping you?
<b> is_number function return Y for numbers and N for characters </b>

SQL> get is_number
  1  Create or Replace
  2  Function IS_number
  3   (vString       in Varchar2,
  4    nStart_pos    in Number,
  5    nStop_Pos     in Number)
  6  Return varchar2 is
  7  nTest_Num     Number := 0;
  8  nbegin_pos    Number := Nvl(nStart_pos, 1);
  9  nEnd_Pos      Number :=  nvl(nStop_Pos, Length(vString));
 10  vSuccess_Flag Varchar2(1);
 11  Begin
 12     Begin
 13        IF vString is Null Then
 14           nTest_Num := 'test';
 15        End IF;
 16        nTest_Num     := To_Number(substr(vString, nBegin_Pos, nEnd_Pos));
 17        vSuccess_Flag := 'Y';
 18      Exception
 19          When Invalid_Number Then
 20               vSuccess_Flag := 'N';
 21          When Others Then
 22               vSuccess_Flag := 'N';
 23     END;
 24     Return vSuccess_Flag;
 25* END;
SQL> /

Function created.
SQL> ed
Wrote file afiedt.buf

  1  select     is_number(empno,1,length(empno)) empno,
  2     is_number(job,1,length(empno)) job ,
  3*    is_number(empno||job,1,length(empno||job)) empnojob from emp
SQL> /

EMPNO      JOB        EMPNOJOB
---------- ---------- ----------
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N
Y          N          N

14 rows selected.
general solution for tour query... [message #39059 is a reply to message #39019] Mon, 10 June 2002 23:37 Go to previous message
Amit
Messages: 166
Registered: February 1999
Senior Member
CREATE OR REPLACE FUNCTION Test_Alpha
(pass_val IN VARCHAR )
RETURN VARCHAR
IS
lv1 VARCHAR2(3);
lv_var1 VARCHAR2(3);

BEGIN

IF (TRANSLATE(UPPER(pass_val),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', RPAD('x',26,'x') )=RPAD( 'x', LENGTH(pass_val),'x'))THEN
lv_var1 :=pass_val;
RETURN lv_var1;
ELSE
RETURN NULL;
END IF;

END;
/
Previous Topic: Re: define view column as a PL/SQL functon
Next Topic: select unique rows
Goto Forum:
  


Current Time: Mon May 20 16:20:21 CDT 2024