I have found this answer useful:
Accent and case insensitive COLLATE equivalent in Oracle, but my question is regarding LIKE searching with a version 9 Oracle db.
I have tried a query like this:
SELECT column_name
FROM table_name
WHERE NLSSORT(column_name, 'NLS_SORT = Latin_AI')
LIKE NLSSORT('%somethingInDB%', 'NLS_SORT = Latin_AI')
but no results are ever returned.
I created a little Java file to test:
import org.apache.commons.dbcp.BasicDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class DbCollationTest
{
public static void main(String[] args) throws SQLException
{
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
dataSource.setUrl("url");
dataSource.setUsername("usr");
dataSource.setPassword("pass");
Connection conn = null;
PreparedStatement createStatement = null;
PreparedStatement populateStatement = null;
PreparedStatement queryStatement = null;
PreparedStatement deleteStatement = null;
ResultSet rs = null;
try
{
conn = dataSource.getConnection();
createStatement = conn.prepareStatement("CREATE TABLE CollationTestTable ( Name varchar(255) )");
createStatement.execute();
String[] names = { "pepe", "pépé", "PEPE", "MEME", "mémé", "meme" };
int i = 1;
for (String name : names)
{
populateStatement = conn.prepareStatement("INSERT INTO CollationTestTable VALUES (?)");
populateStatement.setString(1, name);
populateStatement.execute();
}
queryStatement = conn.prepareStatement("SELECT Name FROM CollationTestTable WHERE NLSSORT(NAME, 'NLS_SORT = Latin_AI') LIKE NLSSORT('%pe%', 'NLS_SORT = Latin_AI')");
rs = queryStatement.executeQuery();
while (rs.next())
{
System.out.println(rs.getString(1));
}
deleteStatement = conn.prepareStatement("DROP TABLE CollationTestTable");
deleteStatement.execute();
}
finally
{
//DBTools.tidyUp(conn, null, rs);
//DBTools.tidyUp(createStatement);
//DBTools.tidyUp(populateStatement);
//DBTools.tidyUp(queryStatement);
//DBTools.tidyUp(deleteStatement);
}
}
}
I have not had any success googling, anyone have any solutions?
I want to perform a search on part of a name and return results that are matched using case and accent insensitivity.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…