Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use parameter in like clause in oracle

Tags:

asp.net

oracle

I'm trying to build a search page in ASP.NET that allows me to search for table names in oracle. When I place the sql in the sqldatasource control it doesn't recognize the parameter :Tablename. How do I need to rewrite this so that it works?

SELECT Owner, Table_name, Num_Rows, Tablespace_name
FROM all_tables
WHERE trim(upper(table_name)) LIKE trim(upper('%:TableName%'))
like image 899
FashionHouseJewelry.com Avatar asked Aug 07 '09 14:08

FashionHouseJewelry.com


People also ask

Can we use like operator in if condition in Oracle?

the LIKE operation is not permitted to be used with IN.

What can I use instead of like operator Oracle?

You can also using the % wildcard multiple times within the same string. For example, SELECT last_name FROM customers WHERE last_name LIKE '%er%';

Where can a be used in like conditions in PL SQL?

Description. The SQL LIKE condition allows you to use wildcards to perform pattern matching in a query. The LIKE condition is used in the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement.


2 Answers

Can you replace

'%:TableName%'

with

'%' || :TableName || '%'

?

like image 133
Adam Paynter Avatar answered Oct 11 '22 02:10

Adam Paynter


For those that might be interested: For SQL Server embedding the % into the parameter's text like this works: (The other method described above doesn't)

WHERE trim(upper(table_name)) LIKE trim(upper(@TableName))
like image 31
Jeff Avatar answered Oct 11 '22 01:10

Jeff