Function to check whether a value is NUMERIC

Hi
I have a requirment, where I need to check for a field whether it contains a valid numeric value or not.
Could you please suggest a function.
If I use TO_NUMBER(VAL1) it throws an exception in case of an non_numeric value.
The requirement is as follows.
If the field 'val1' contains a numeric value then the function should return the coressponding nueric value. If it is not,then return a boolean value are a return code instead of exception.
Is there are built in function in ORACLE to acheive the same , please advice.

Hi,
The best way to do it is using User Defined Function, i have written a function as per your Requirement...It is give the data if it is numeric else it will return FALSE
create table Testdata
as
select '10' n from dual
union all
select 'xx' from dual
union all
select '20' from dual
union all
select '3YY' from dual;
CREATE OR REPLACE FUNCTION IsNumeric
(p_col_value IN VARCHAR2)
RETURN     VARCHAR2
AS
v_val NUMBER;
BEGIN
v_val := TO_NUMBER (p_col_value);
RETURN 'TRUE';
EXCEPTION
WHEN VALUE_ERROR THEN
          RETURN 'FALSE';
     WHEN OTHERS THEN
          RETURN 'FALSE';
END IsNumeric;
Select Decode(IsNumeric(n),'TRUE',n,'FALSE') from Testdata
Regards
kamal

Similar Messages

  • Writing a function to find whether a value is present in a sql query output

    Hi gurus,
    I would like to write a function to which i will pass a value and a sql query as parameters.
    Now the function needs to execute that sql query and find whether the given value is present in the output list
    when the query is executed. If it is present it should return 'T' otherwise 'F'
    My function will look like
    CREATE FUNCTION CHECK_VALUE(VALUE VARCHAR2,V_SQL VARCHAR2) RETURN VARCHAR2
    SELECT CHECK_VALUE('Dallas','SELECT LOCATION_CODE FROM HR_LOCATIONS')
    It should check whether the value 'Dallas' is present in the output list returned by the sql query.
    Any help will be appreciated.
    Thank you.

    CREATE OR REPLACE
      FUNCTION CHECK_VALUE(
                           VALUE VARCHAR2,
                           V_SQL VARCHAR2
        RETURN VARCHAR2
        IS
            RETVAL VARCHAR2(4000);
            REFCUR SYS_REFCURSOR;
        BEGIN
            OPEN REFCUR FOR V_SQL;
            LOOP
              FETCH REFCUR INTO RETVAL;
              EXIT WHEN REFCUR%NOTFOUND;
              IF RETVAL = VALUE
                THEN
                  CLOSE REFCUR;
                  RETURN 'T';
              END IF;
            END LOOP;
            CLOSE REFCUR;
            RETURN 'F';
    END;
    Function created.
    SQL> SET SERVEROUTPUT ON
    SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('DALLAS','select loc from dept'));
    T
    PL/SQL procedure successfully completed.
    SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('PARIS','select loc from dept'));
    F
    PL/SQL procedure successfully completed.
    SQL> SY.

  • Any function to check the input value is integer?

    May I know if there's any function to check the input value is integer in Form 4.5?
    Thanks.

    just to add :) - (couldn't resist) :
    create or replace function is_integer ( p_number in varchar2 ) return boolean is
      v_return boolean := true;
      v_number number;
    begin
      v_number := p_number;
      if v_number != trunc(v_number) then
        v_return := false;
      end if;
      return v_return;
    exception
      when others then
        v_return := false;
        return v_return;
    end;
    begin
      if not is_integer(1.1) then
        dbms_output.put_line('is not');
      end if;
      if is_integer(1) then
        dbms_output.put_line('is');
      end if;
      if not is_integer('a') then
        dbms_output.put_line('is not');
      end if;
    end;

  • Finding function to check whether this employee has changed Employee group

    I'm finding function to check whether this employee has changed Employee group from Temporary to Regular during the year or not.
    Is there any PY function can check as above condition?
    Thank you

    Hi,
    You have to read IT0001 data for reading Employee Group or Sub Group Change. Use the FM HRREADINF* to read IT0001 Data.
    Thanks & Regards,
    Sandip

  • Is there any function to check whether table exist in the dictionary

    In the program, i want to dynamicly check whether the table exists in the dictionary, and return the result to me.

    hi
    good
    i dont think there is any such function to check the presence of the table.
    bcz you can check it directly in se11 rather than using any function.
    thanks
    mrutyun^

  • How to check whether a value is empty in ABAP Sql

    Select matnr from mara where
    MARA~LVORM is null
    Basically if LVORM is blank, i.e., not popoulated, I want to get matnr.
    Will above query accomplish this in ABAP OPEN SQL.

    Hi,
    LVORM column is defined as a NOT NULL column.. so the values will be either a initial value (space, in this case) or filled with some value
    SELECT matnr
      INTO TABLE t_matnr
      FROM mara
      WHERE LVORM = space.
    https://cw.sdn.sap.com/cw/docs/DOC-40206
    http://learnsapmdm.blogspot.com/2009/01/data-modelling-and-database-design-in.html
    regards,
    Paulo Carvalho

  • How to check value is numeric or not

    hi how to check whether a value is numeric or not.
    example.  data : x type n.
              x = 12345.
    Now how to check whether X contains numeric value or not.

    Hi,
         If your type is 'N' there is no way that 'X' can have any value apart for numberics (i.e. 0 - 9).
    You can also check that as follows.
    Data: num_list(10) type c value '0123456789',
          x type n.
    X = '12345'.
    This is more useful if your X is of type C.
    if X CO num_list.
    Its only numeric
    else.
    its contains non numeric
    endif.
    Regards,
    Sesh

  • Built-in functions to check for numeric or string

    Hi,
    Is there any built-in functions in java for checking if the value is numeric or is a string ?
    tks & rdgs

    Hi,
    I have a string og such value "1 testing" that i will be using stringtokenzier to get the individual parts but i do not want to return "1" but only "testing" so i'll need to check whether if the parts can be converted to numeric if so , then i don't return else return the value
    tks & rdgs

  • Want  to check whether input field in selection-screen is numeric or not

    i have a select -option in  selection-screen  in which user enters a value.i just want to check if this value is numeric then it should  be 18 positions prefixed with zeroes if numeric like 000000000000400000  and needs to be left justified if not numeric like G0032-BTI.
    i check the fourm also but it didn't helped me.
    i m using the code.
    SELECT-OPTIONS : S_MAT FOR CDHDR-OBJECTID,
    LOOP AT S_MAT.
    if  S_MAT ca sy-abcde  .
      shift s_mat left deleting leading space.
    else.
        SHIFT s_mat RIGHT DELETING TRAILING SPACE.
        TRANSLATE s_mat USING '0'.
    ENDIF.
    endloop.
    can anybody help.
    <REMOVED BY MODERATOR>
    thanks
    Edited by: Alvaro Tejada Galindo on Jan 17, 2008 4:00 PM

    I have a solution for you! Try this code below, just copy/paste "as-it-is".
    TABLES: cdhdr.
    DATA: gv_type TYPE dd01v-datatype.
    SELECT-OPTIONS : s_mat FOR cdhdr-objectid.
    AT SELECTION-SCREEN.
      LOOP AT s_mat.
        CLEAR gv_type.
        IF NOT s_mat-low IS INITIAL.
          CALL FUNCTION 'NUMERIC_CHECK'
            EXPORTING
              string_in = s_mat-low
            IMPORTING
              htype     = gv_type.
          IF gv_type NE 'NUMC'.
            MESSAGE e016 WITH 'Not Numeric'.
          ELSE.
            SHIFT s_mat-low LEFT DELETING LEADING: '0', space.
            CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
              EXPORTING
                input  = s_mat-low
              IMPORTING
                output = s_mat-low.
            MODIFY s_mat TRANSPORTING low.
          ENDIF.
        ENDIF.
        IF NOT s_mat-high IS INITIAL.
          CALL FUNCTION 'NUMERIC_CHECK'
            EXPORTING
              string_in = s_mat-high
            IMPORTING
              htype     = gv_type.
          IF gv_type NE 'NUMC'.
            MESSAGE e016 WITH 'Not Numeric'.
          ELSE.
            SHIFT s_mat-high LEFT DELETING LEADING: '0', space.
            CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
              EXPORTING
                input  = s_mat-high
              IMPORTING
                output = s_mat-high.
            MODIFY s_mat TRANSPORTING high.
          ENDIF.
        ENDIF.
      ENDLOOP.
    I hope this solves your problem.
    Cheers,
    Sougata.

  • How to check the numerica value

    Dear Experts,
    Would you please show me the code how to check a character value is numeric or not, include negative sign '-'.
    For example the character value (01.-10) should not be a good numeric value use in later.  the (-1.00) should be a good numeric value.
    Thanks,
    Helen

    Hello,
    Use the FM <b>NUMERIC_CHECK</b>
    Regards,
    Vasanth

  • How to check sign of value ' - ' and ' + '.

    Hi Experts,
            can you tell me what is the preocedure to check the sign
    of value whether it would be ' - ' or ' + '.
             if i have to check the sign of -1100 then system should tell me the sign is ' - ' . how it can be possible.

    Hi,
    Try this.
    Check whether the value of variable say v1.
    If v1< 0.
    Then display the message as '  -  '.
    else.
    Then display the message as '  + '.
    endif.
    The message is according to your requirement.
    Sharin.

  • How can I check whether or not an database table exists?

    Hi,
    I am new to ABAP programming. And now I want to write an function that check whether an table exists in the dictionary.
    It request the table name was given by the user input. So I have to check it dynamically.
    Please give me some guide if you know about that.
    Thanks.

    Hi,
    All the table names exist in DD02l table.
    Fetch data from DD02l table by passing selectin screen parameter .
    REPORT ysdn_new .
    PARAMETERS: p_tab LIKE dd02l-tabname.
    DATA: v_tab LIKE p_tab.
    SELECT SINGLE tabname INTO v_tab FROM dd02l WHERE tabname = p_tab.
    WRITE v_tab.
    If ypu want to fetch from TADIR table only means you have to pass selection screen parameter in place of obj_name and TABL for OBJECT field.
    SELECT SINGLE tabname INTO v_tab
    FROM TADIR
    WHERE obj_name = p_tab
       AND    object = 'TABL'.
    This is other way of getting table name by passing selection screen parameter
    this will work.
    Please reward points if helpful...
    Regds
    Sivaparvathi

  • How to check whether a field contains at least one numeric value

    how to check whether a field contains at least one numeric value..

    Hi,
    I hope that this code will works.
    constants:
       c_digit_grp        TYPE char11         VALUE '0123456789',        " Digit group
    * Data Declaration
    data :
      str   type string.
    * if you want check entire string and pass entire string
    if  str CA c_digit_grp.
    * write your logic ---this block will execute atleast one numeric value exists in the string
    Endif.
    Regards
    Bhupal Reddy

  • Invalid function body condition: ORA-06502: PL/SQL: numeric or value error:

    I'm trying to customize my link column on an interactive report to branch to another page in my application based on a pl/sql call. My condition type for the link column is pl/sql function body returning a boolean. I'm calling a packaged function that returns a boolean but receive the following error:
    Invalid function body condition: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    This is my code:
    return files_util.list_files('test','test');
    I've tried running the same code in sqlplus and it works fine. Any help would be appreciated.
    Thanks,
    Rob

    It turns out I had multiple issues. I thought the code I was running for the link column would be executed and let me branch to another page to view the results of my pl/sql code. It appears that the pl/sql code for the link column only controls whether the link is displayed or not. The reason for the ora-6502 was because a variable in my pl/sql function was not large enough to hold a value based on the userid signing onto the application. I'm using database authentication so I thought that the userid in apex would be my database userid which is only 4 characters. The userid actually used is apex_public_user which caused by ora-6502 error.

  • Function module to check whether Goods Receipt of a Purchase Order is done.

    Hi,
    Is there any function module to check whether Goods Receipt of a Purchase Order is already done?
    Taking into consideration reversals.
    Thanks.

    Hi,
    I think u can do this by using a simple select query.
    u have to go in EKBE table.
    put the PO no. in field EBELN + EBELP(line item)  and get the material docuement no.  in field BELNR + BUZEI(line item).
    Thanks
    Jitendra

Maybe you are looking for

  • Sort photos by time created

    I use more than one camera at events and each camera has a specific prefix on the photo numbers (ex. EW1_ and EW2_).  I'd like to be able to sort these photos by time created rather than date created so they are listed in an order of how the event ha

  • FnF Error when file is there Please Help

    I'm working on a school project and i have an encryption funcion, it creates a keyfile and then when you try to login it reads that keyfile and and decrypts the password and checks the password given by the user. i have this code try {           Obje

  • EMF file opens as blank

    I am trying to open an emf file in Illustrator, but it just appears as a blank page.  I tried some emf files that I created a few years ago, and they open fine.  But the new ones that I made are not appearing.  What am I doing wrong? 

  • FTTP install - size of fibre tube from ONT to CSP

    Hello all, I am now finally able to order fibre where I live and so have ordered the Infinity 3 package.  This is a mixed copper and fibre development, with only copper deployed after moving in a year ago (so currently on ADSL).  The fibre was run to

  • ITunes Store download problems

    Hi, for the last few months if I purchase something on the iTunes store (Apps, Music, TV Shows, Movies) regardless of what it is the purchase is made and it downloads fine. However, if I close iTunes before the download is completed, whatever was in