Reputation: 11
I have a problem with the following:
I have a sequence that comes with the value:
"ORA-00904: TESTE: identificador inválido"
I need to replace this test field to empty ( '') in my query .
But if my query contains other field with the name for example TESTETE and I replace for '', it staies wrong, replacing TESTE for and TESTETE for
TE
I want to replace the TESTE for `` and the TESTETE let how it is.
my example query is :
SELECT TESTE, TESTETE, fld1 FROM TBL
My logic is as follows:
String oracleMsg = "ORA-00904: TESTE: identificador inválido";
String query = "SELECT TESTE, TESTETE, OUTRO FROM TBL";
String comp = "TESTE";
if (oracleMsg.contains(comp)){
query = query.replace(comp, "''");
}
System.out.println(query);
Result: SELECT '', ''TE, OUTRO FROM TBL Expected Result? SELECT '', TESTETE, OUTRO FROM TBL
Thank you a lot!!!
Upvotes: 0
Views: 72
Reputation: 111219
Use regular expressions and surround your pattern with word-boundary anchors.
query = query.replaceAll("\\b"+comp+"\\b", "''");
In case you want to replace only one instance of the pattern, use replaceFirst
instead of replaceAll
.
Upvotes: 1