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

Thread: Search a table for a specific value

  1. #1
    Join Date
    Mar 2001
    Posts
    82
    Hi,

    I know I've seen this somewhere.
    How do I search a table to see if it contains a specific value?

    Ex: If I have 1000 names and I want to see if there is anyone named 'Smith'. I don't want to search
    the whole table. I want to stop when I find a record with the name 'Smith' and return a value
    (0 or 1 I guess) depending on wherther I find it or not.

    Thanks

  2. #2
    Join Date
    Feb 2001
    Posts
    66
    If you whant to stop searching after first finding, use the hint /*+first_rows */ in your SELECT query.

  3. #3
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135

    Select * from emp
    where name like '%Smith%'
    and rownum = 1
    ;

  4. #4
    Join Date
    Sep 2001
    Location
    NJ, USA
    Posts
    1,287
    select 1 from dual
    where exists (select 1 from emp where name like '%Smith%' )
    union
    select 0 from dual
    where not exists (select 1 from emp where name like '%Smith%' )

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