Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if a value exists in the table 1

Status
Not open for further replies.

Zargo

Programmer
Mar 21, 2005
109
0
0
Hi All,

I have a table with the following content:

TableB
ColumnA

1034%
2900%
3444%
10%

(the percent signs in the tables are wildcards)

I have a value 103459 (its a variable) and i want to check if this exists in the table; this value exists in the table because we have a value in the table 1034%. Our value begins also with 1034....

I want to return a 'x' if this exists in the table. The query should look like:

select 'x' from anytable where rownum = 1 and '103459' like (select
replace(columnA,'%','') from tableB)

But this doesnt work, anybody idea how to setup this query?

TIA,
Zargo
 
Zargo,

Here are your sample data:
Code:
SQL> select * from tableb;

COLUMNA
----------
1034%
2900%
3444%
10%
...and here is your code to produce the results you wanted:
Code:
Select 'x' result from dual
 Where exists (select null from tableB
                where 103459 like columnA);

RESULT
------
x
...and proof that no rows result when the test value does not match:
Code:
Select 'x' result from dual
 Where exists (select null from tableB
                where 666 like columnA)
/

no rows selected
Let us know if you have questions.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top