Search * from t where a like b case-insensitive ?
I have a Database-field (CHAR60) that contains text with upper and lower case letters. In my application, the user can search for entries in the DB table using this field, which leads to an SQL statement like this:
SELECT * FROM table WHERE field LIKE pattern INTO...
My question:
If I search for "abc", i won't find entries with "aBc". Can I do a case-insensitive search with SELECT and LIKE?
Hello Daniel,
What is the domain(CHAR60) for the field that you are searching for?
The domain has an attribute called <i>Lowercase</i>, and it is my understanding that so long as this is checked, the data will be stored in the database exactly like it was entered on the screen (case-sensitive).
If thst is the case with your domain, then I guess you would have to make do with something like:
SELECT *
FROM table.
TRANSLATE : TABLE-FIELD TO UPPERCASE,
PATTERN TO UPPERCASE.
IF TABLE-FIELD CS PATTERN.
* Do your processing here...or fill the internal table
ENDIF.
ENDSELECT.
I know this code has been a bit crude, but this is the essence.
Regards,
Anand Mandalika.
Similar Messages
-
SELECT * FROM mytable WHERE ANYCOLUMN like myString
Hi ALL,
Is there a way i can select a row wherein any of the columns contain my search string?
SELECT *
FROM mytable
WHERE ANYCOLUMN like '%myString%'Thanks!
BROKENExample of it working...
SQL> var val varchar2(5)
SQL> exec :val := 'KING'
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1 select distinct substr (:val, 1, 11) "Searchword",
2 substr (table_name, 1, 14) "Table",
3 substr (t.column_value.getstringval (), 1, 50) "Column/Value"
4 from cols,
5 table
6 (xmlsequence
7 (dbms_xmlgen.getxmltype ('select ' || column_name
8 || ' from ' || table_name
9 || ' where upper('
10 || column_name
11 || ') like upper(''%' || :val
12 || '%'')'
13 ).extract ('ROWSET/ROW/*')
14 )
15 ) t
16 where table_name = 'EMP'
17* order by "Table"
SQL> /
Searchword Table Column/Value
KING EMP <ENAME>KING</ENAME>
SQL> -
Select * from tbl where product like ('abc','def','rgh');
Hi Guys,
My requirement is I need to filter by providing date value with some of the porduct details and prod_id may differ with product like
prod_id product date
01 abc 01/2012
02 abc 02/2012
03 def 03/2012
How can we put multiple text conditions using LIKE operator in where clause of the sql query.
if we use union to combine all the sql queries, how can we filter by entering date value.
SQL>select * from tbl where product like ('abc','def','rgh');
Please provide any ideas on the same.
Thanks in advance!
-LKselect * from tab1 where regexp_like(product,'^abc|def|rgh');
-
Select ename from emp where ename like LIKE 's%';
Hi friends,
select ename from emp where ename like LIKE 's%';
output am geting like this naseer
anusha
basha
But I want to display like this naeer anuha baha784585 wrote:
Hi friends,
select ename from emp where ename like LIKE 's%';
output am geting like this naseer
anusha
basha
But I want to display like this naeer anuha baha
Use REPLACE function:
SQL> select replace('naseer','s','') replace from dual;
REPLACE
naeerKamran Agayev A.
Oracle ACE
My Oracle Video Tutorials - http://kamranagayev.wordpress.com/oracle-video-tutorials/ -
Select * from TABLE where Filed like pa_input.
Hello,
the following works fine
select * from ZTABLE INTO wa_myarea WHERE myfield LIKE 'a%'.
Now I don't want to hard code the selection criteria for myfield, but let the user select one, so I did:
parameters pa_input type mytype.
select * from ZTABLE INTO wa_myarea WHERE myfield LIKE pa_input.
If the user enters now for example a% everything works again fine. But I assume that a user rather would enter a* for a wild card search and that doesn't work. Do I have to manually replace all * in my variable with % before I run the select statement? I hope not... What would be the best way?
Thanks.Moderator message - Please do not ask basic questions - thread locked
Rob -
Case Insensitive Search coupled with "LIKE" operator.
Greetings All, I am running Oracle 11gR1 RAC patchet 25 on Windows X64.
This db supports and application that requires case insensitive searches.
Because there are a few entry points into the db I created an "after login" trigger:
CREATE OR REPLACE TRIGGER MyAppAfterLogon_TRGR
AFTER LOGON
ON DATABASE
DECLARE
vDDL VARCHAR2(200) := 'alter session set nls_comp=''linguistic''';
vDDL2 VARCHAR2(200) := 'alter session set nls_sort=''binary_ci''';
BEGIN
IF ((USER = 'MyAppUSER') OR(USER = 'MyAppREPORTINGUSER')) THEN
EXECUTE IMMEDIATE vDDL;
EXECUTE IMMEDIATE vDDL2;
END IF;
END MyAppAfterLogon_TRGR;
This ensures that everyone connecting to the DB via any mechanism will automatically have case insensitive searches.
Now, to optimize the know queries I created the standard index to support normal matching queries:
select * from MyTable where Name = 'STEVE';
The index looks like:
CREATE INDEX "CONTACT_IDX3 ON MYTABLE (NLSSORT("NAME",'nls_sort=''BINARY_CI'''))
This all works fine, no issues.
The problem is when I write a query that uses the "LIKE" operator:
select * from MyTable where Name like 'STEV%';
I get back the record set I expect. However, my index is not used? I can't for the life of me get this query to use an index.
The table has about 600,000 rows and I have run gather schema stats.
Does anyone know of any issues with case insensitive searches and the "LIKE" clause?
Any and all help would be appreciated.
LI think there is issue with your logon trigger :
"IF ((USER = 'MyAppUSER') OR(USER = 'MyAppREPORTINGUSER')) THEN"
it should be :
IF UPPER(USER) = 'MYAPPUSER' OR UPPER(USER) = 'MYAPPREPORTINGUSER' THEN
because user name stored in Upper case. Check and try.
HTH
Girish Sharma -
Delete from wwv_flow_file_objects$ where file name like 'p1_name'
I am having an issue deleting an object in my apex application. I have uploaded an object into the application i can open the application but i cannot delete from that application. I can delete it when i login to the server and provide this command:
delete from wwv_flow_file_objects$ where filename like 'Whatever.pdf';
I am looking for the code to assign to a button and how do i get it to process.
process
the code i currently have is this: DELETE from APEX_APPLICATION_FILES WHERE name = :P4_NAME and it is not working. What am i missing.
process point = on submit
run process = once per session
when button is pressed pdf_remove
name: pdf_delete
button:
action when clicked
action - submit page
execute validation - no
database action - no database action "it does not show my process"Christian
Thank you very much,
I switched to Apex Listener over Weblogic Server that was already working, just added a new managed server and deployed apex.war and i.war on it.
the server resources are very good now. -
Possible to do case-insensitive searches?
G'day,
I was wondering if it's possible to do case-insensitive searches in oracle/HTMLDB?
I've tried what I thought would work
"select * from application where name like '%microsoft%'", this unfortunately doesn't return any records with a capital in it(eg "Microsoft").
If there is no way to do case-insensitive searches what is the best way around it?
Thanks
-ColinColin,
Yes it is possible to do case insensitive searches using SQL. Try, for example:
select * from application where upper(name) like '%ORACLE%'
The trick is to upper() both sides of the like operator.
Sergio -
Case insensitive search and index
I have to execute a case insentitive search.
I created this index on a not null field:
create index indx_prova on
table (nlssort(campo, 'NLS_SORT=BINARY_CI'));
The select is:
select * from tabella where campo like 'A storage%'
This select should retrive 5 records:
A storage ring for crystalline beam studies
a storage ring for crystalline beam studies
A Storage Ring for Crystalline Beam Studies
A storage ring for crystalline beam studies
A storage ring for crystalline beam studies
Instead I got only 3 records:
A storage ring for crystalline beam studies
A storage ring for crystalline beam studies
A storage ring for crystalline beam studies
So The query isn't case insensitive.
I can't set nls_sort=BINARY_CI and nls_comp=LINGUISTIC at level session.
Is there a solution.
Am I doing something wrog?I set alter session set nls_comp=LINGUISTIC; alter session set nls_sort=BINARY_CI;
I create this index:
create index titolo_indx on
table (nlssort(campo, 'NLS_SORT=BINARY_CI'));
If I execute this query:
select * from ri01_prodotti where titolo like 'A storage ring f%'
Oracle doesn't user the index.
SQL_ID 7yvspnyf96vp8, child number 0
select * from ri01_prodotti where titolo like 'A storage ring%'
Plan hash value: 350479533
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 2020 (100)| |
|* 1 | TABLE ACCESS FULL| TABLE | 1 | 1365 | 2020 (1)| 00:00:25 |
Predicate Information (identified by operation id):
1 - filter("CAMPO" LIKE 'A storage ring%')
If I execute a query with =, oracle use index.
select * from table where campo ='A storage ring for crystalline beam studies'
SQL_ID 5jzr5nm6b37pq, child number 0
select * from ri01_prodotti where titolo ='A storage ring for crystalline beam
studies'
Plan hash value: 3866031381
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 151 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID| RI01_PRODOTTI | 377 | 502K| 151 (0)| 00:00:02 |
|* 2 | INDEX RANGE SCAN | TITOLO_INDX | 151 | | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("RI01_PRODOTTI"."SYS_NC00078$"=HEXTORAW('612073746F726167652072696E6720
666F72206372797374616C6C696E65206265616D207374756469657300') ) -
Search on text with diacritic, and case insensitive
Hello to all,
I'm using this condition in a query on XML:
field[contains(@value, "gangesa" )
If @value= 'Gaṅgeśa' I'd like to get this record also by using the word: "gangesa" So I need to map:
ṅ = n
ś = s
And do it in case insensitive. Somebody can help me?
Thank you,
CristianALTER SESSION SET NLS_COMP=LINGUISTIC;
ALTER session set nls_sort='binary_ai'; -->accent insensitive
binary_ci -->case insensitive.
with t as
(select 'Gageśa' col1 from dual union all
select 'GAgEśa' from dual union all
select 'gagEśA' from dual union all
select 'not Gageśa' from dual
select * from t where col1 like '%gagesa';
Gagesa
GAgEsa
gagEsA
not Gagesaand do the search.
Edited by: PhoenixBai on Aug 25, 2010 10:14 PM -
How to search case insensitive ?
Is there any way to search case insensitive ?
Because we use Remedy application, we can't change query like to use 'UPPER' or 'LOWER' functions.
For example,
SQL> desc test1
Name Null? Type
A VARCHAR2(20)
SQL> select * from test1;
A
TEST
test
SQL> select * from test1 where A like 'TE%';
then I expect result as following:
A
TEST
test
Please advise..If you can't change the query or schema then I'm afraid you are pretty much stuck. You can use a function based index if you stop using a wildcard (% forces a full-table scan and, therefore, does not use the index). If you had more control over the app, the context index would be good. Storing the data in all uppercase is another solution. All of the solutions are controled by the app vendor though.
My advice - log an enhancement with Remedy...suggest using a context index on the column in question. -
How can I execute a case-insensitive search?
I have created a table
CREATE TABLE parsPatient
patPARSID VARCHAR2(40),
patFirstName VARCHAR2(30),
patMiddleName VARCHAR2(30),
patLastName VARCHAR2(30),
patDOB DATE,
CONSTRAINT parsPatient_PK PRIMARY KEY (patPARSID) ENABLE
)and I would like to search the patLastName field for all patients that match a wildcard (i.e. I want to see Abcd, ABcd, AB, and abcd when I search for "AB%".
Using Oracle Database 10g Express Edition (10.2), I have done the following successfully:
SQL> alter session set nls_comp='LINGUISTIC';
SQL> select count(patparsid) from parspatient where patlastname like 'ab%';
COUNT(PATPARSID)
7However, when I try to do this using .NET, I get 0 rows. I'm doing the following (simplified, hopefully, for posting):
DataSet dsResults = new DataSet("patients");
try
// Establish connection
OracleConnection cn = new OracleConnection();
cn.ConnectionString = settings.ConnectionString;
cn.Open();
cn.ClientId = settings.CurrentUser;
// Set the linguistic mode
OracleCommand command = new OracleCommand();
command.Connection = cn;
command.BindByName = true;
command.CommandText = "ALTER SESSION SET NLS_COMP='LINGUISTIC'";
command.CommandType = CommandType.Text;
command.Parameters.Clear(); // Remove all parameters, if any.
int iValue = command.ExecuteNonQuery(); // This returns a -1 -- is that normal?
command.CommandText = "ALTER SESSION SET NLS_COMP='ANSI'";
iValue = command.ExecuteNonQuery();
command.CommandText = "SELECT patPARSID FROM parsPatient WHERE patLastName LIKE 'ab%'";
OracleDataAdapter adapter = new OracleDataAdapter();
adapter.SelectCommand = command;
adapter.Fill(dsResults, "SearchResults");
// Clean up
command.Dispose();
command = null;
cn.Close();
cn.Dispose();
cn = null;
catch (OracleException oex)
LogDBError("TestCaseInsensitiveSearch", oex);
Any help/pointers would be greatly appreciated!Hi,
I think the Express Edition comes with the HR sample schema, so here is a quick and dirty sample that uses the HR schema:
using System;
using System.Data;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
namespace CaseInsensitiveTest
class Program
// change connection string for your env.
private const string constr = "user id=hr; password=hr; data source=lt10gr2; enlist=false; pooling=false";
// simple statement for testing
private const string sql = "select last_name from employees where last_name like 'a%' order by last_name";
static void Main(string[] args)
// get a connection
OracleConnection con = new OracleConnection(constr);
con.Open();
// get globalization object to set values
OracleGlobalization glb = OracleGlobalization.GetThreadInfo();
glb.Sort = "BINARY_CI";
glb.Comparison = "LINGUISTIC";
// set new globalization (nls) values for the session
con.SetSessionInfo(glb);
// get command object and set statement to execute
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = sql;
// get a data reader
OracleDataReader dr = cmd.ExecuteReader();
// loop through the reader and display names
while (dr.Read())
Console.WriteLine("Last Name = {0}", dr[0].ToString());
// clean up
glb.Dispose();
cmd.Dispose();
con.Dispose();
}The above code should result in:
Last Name = Abel
Last Name = Ande
Last Name = Atkinson
Last Name = AustinHope that helps a bit.
- Mark -
How to search Database in JSP using LIKE
hi can anyone tell me is there any other syntax for Query when we use LIKE to search database in which suppose
String para = request.getParameter("name");
Select name,surname From user where name LIKE '"+para+"';hi,
which database are you using, some require you to put % sign with like
e.g. select xyz from table abc where xyz like '%"+para+"%' -
Like Query with Case insensitive
Hi ,
I have select query with Like, need to add case insenstive for that.
E.g
Select * from emp where empname like ('D%').
The above query will fetch only names starting with 'D' not the name starting with 'd'.But i need to fetch all the name starting with D or d. Can anyone help me out with this query.
Thanks
DuraiHi
Use uppercase for example:
Select * from emp where upper(empname) like ('D%');
Ott Karesz
http://www.trendo-kft.hu -
Where columnname like '%somevalue' causing full table scan
hi,
10.2.0.4 database
is it possible to force an index scan over a full table scan if I use a where clause similar to the following:
where col1 like '%somevalue';
There is an index with col1 as the first segment of the index and another column as the second segment of the index.
Thanks
JOhnI have done it for you
SQL> create index empX on emp(job) ;
Index created.
SQL> explain plan for select * from emp where job like '%ERK' ;
Explained.
SQL> select * from table(dbms_xplan.display) ;
PLAN_TABLE_OUTPUT
Plan hash value: 3956160932
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 37 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP | 1 | 37 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("JOB" LIKE '%ERK')
13 rows selected.
SQL> explain plan for select * from emp where job like 'C%ERK' ;
Explained.
SQL> select * from table(dbms_xplan.display) ;
PLAN_TABLE_OUTPUT
Plan hash value: 140376749
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 4 | 148 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 4 | 148 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | EMPX | 4 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("JOB" LIKE 'C%ERK')
filter("JOB" LIKE 'C%ERK')
15 rows selected.
SQL> explain plan for select /*+index (emp,EMPX) */ * from emp where job like '%ERK' ;
Explained.
SQL> select * from table(dbms_xplan.display) ;
PLAN_TABLE_OUTPUT
Plan hash value: 3745534319
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 37 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 37 | 2 (0)| 00:00:01 |
|* 2 | INDEX FULL SCAN | EMPX | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter("JOB" LIKE '%ERK')
14 rows selected.SS
Maybe you are looking for
-
How can i get input from user in Workflows
Hello professionals, I'm new to SAP B1 Workflow, i have created some workflows and they all worked fine. But, I am wondering, How can i get input from user?. For example, i want to display list of options to choose between them and route the workflow
-
Sapscript - Output Window twice on one Page
Hi All I am working on a cheque output on pre-formatted paper. the page is split and perforated into 3 pieces 1. Summary 2. Actual Cheque 3. Summary (identical to Part 1) Part 1 and 2 are sent to vendor, and part 3 is kept for our records. I need par
-
Spell checking English and French documents
Hello I have Pages 3.0.2 I write in English and in French and I was not able to find where you can specify the language used in the document so it is spelled correctly Thanks in advance for your help Best Cyril
-
Any issues with Premiere CS5 and CS4 on the same machine?
I want to install the trail version of Premiere CS5, but I want to know if I'll still be able to run CS4 if needed during the trial period, as well as after the trial period if I decide not to upgrade. Does uninstalling CS5 mess up CS4 in any way? J
-
Anbody used Hash partioning? - what about queries not using partition key
Hi there, We have a table, will have over 3 billion rows when loaded and wish to implement partioning. Brief structure cal_id -- relates to date of transaction prod_id cust_id, sales_qty The id's are all surrogate id's/dimension keys About 80% of que