Results 1 to 11 of 11

Thread: Finding Non Numeric Fields in Oracle

  1. #1

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Finding Non Numeric Fields in Oracle

    In vb and i think even in MS SQL server there is a ISNumeric function built in. I know there's no function like that in Oracle (9i), but i was thinking that there might be a logical way to determine if a field is Numeric or Not. Unfortunetly i can't use a stored procedure to do this either. So i'd have to do it in the sql statement itself.

    Does anyone have an idea on how to do this?

    Select Field1 from table_name
    where field1 is NOT numeric

    Thanks
    Andy
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  2. #2
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Finding Non Numeric Fields in Oracle

    Well you could use views like all_tab_columns

    Check the data_type column in all_tab_columns.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  3. #3

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Finding Non Numeric Fields in Oracle

    sorry i'm not trying to find the data type i'm trying to determine whether or not a value is numeric. For instance.

    Field1
    -----
    aasdf
    sdifiue123
    32fafk
    12314
    asdfkj3

    i need a way to filter out the row (12314) and return the rest.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  4. #4
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Finding Non Numeric Fields in Oracle

    try this pl / sql block.
    Code:
    begin
        ......
        BEGIN
           l_test_number := l_string_that_might_hold_a_number;
           .... code that should run when it is in fact a number......
        EXCEPTION
           WHEN OTHERS 
           then
              ..... code that should run when it is in fact NOT a number.....
        END;
        .......
    end;
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  5. #5

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Finding Non Numeric Fields in Oracle

    I saw this on another website, but right now i can't use a stored procedure. So how could i use it in a vb program?
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  6. #6
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Finding Non Numeric Fields in Oracle

    I made an oracle function out of it.


    Code:
    create or replace function isanumber(x varchar2) return boolean
    is
    begin
        declare l_test_number number;
        BEGIN
           l_test_number := x;
           return true;
        EXCEPTION
           WHEN OTHERS THEN
    	return false;
        END;
    end;
    /
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Finding Non Numeric Fields in Oracle

    What about a simple IsNumeric test?

    VB Code:
    1. If Not IsNumeric(field1) then
    2.      Do what you need to do with the record
    3. else
    4.      Throw the record out or do something different with it
    5. end if
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  8. #8

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Finding Non Numeric Fields in Oracle

    i think that is what i'm gonna do. I'd like to use the function that abhijit suggested, but i doubt i have permission to create it. I was hoping there would be just a simple thing to add to my select statement, but i guess not. And i thought that i had seen a function before that would allow me to do it but i can't find it anywhere.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  9. #9
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Finding Non Numeric Fields in Oracle

    space_monkey hang on for a moment before you create the function. i just tested it and its giving me a problem. so let me fix it and then you can have the function.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  10. #10
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Finding Non Numeric Fields in Oracle

    hey I fixed this function. the reason it was throwing an error is that boolean is only available in pl/sql and not in sql. here is my fix.

    Code:
    create or replace function isanumber(x varchar2) return varchar2
    is
    begin
        declare l_test_number number;
        BEGIN
           l_test_number := x;
           return 'true';
        EXCEPTION
           WHEN OTHERS THEN
    	return 'false';
        END;
    end;
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  11. #11

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Finding Non Numeric Fields in Oracle

    Thanks abhijit, I'll try it out.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width