DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: how to find first occurence of character ina string

  1. #1
    Join Date
    Jun 2006
    Posts
    5

    how to find first occurence of character ina string

    In my table i have PHONE NUMBER column.
    the data of this is like 123-23-34567.

    i want to retrive this phone number into 3 separate field of form module.
    example : phno=123-23-34567 then
    1st field 123
    2nd field 23
    3rd field 34567

  2. #2
    Join Date
    Jan 2001
    Posts
    2,828
    Hi

    You need to use instr and substr functions

    select substr('123-23-3456',1,INSTR('123-23-3456','-',1,1)-1) from dual;

    select substr('123-23-3456',INSTR('123-23-3456','-',1,1)+1,
    INSTR('123-23-3456','-',-2,1)-INSTR('123-23-3456','-',1,1)-1)
    from dual

    and so on

    regards
    Hrishy
    Last edited by hrishy; 06-16-2006 at 08:10 AM.

  3. #3
    Join Date
    Nov 2000
    Location
    Potomac, Maryland
    Posts
    85
    You could also use
    select
    substr(phno,1,3) first_field,
    substr(phno,5,2) second_field,
    substr(phno,7,5) third__field
    from table_name

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