0

I need to currently match 00000012345 and 12345 in my DB search query. I am currently using following query:

SELECT * 
FROM BPP.CHECK_REGISTER 
WHERE CHECK_NO like CONCAT('%',:checkNum)

for searching but here % can mean any character other than 0 hence I have replaced this query with following:

SELECT * 
FROM BPP.CHECK_REGISTER 
WHERE REGEXP_LIKE (CHECK_NO,'^(0*12345)$')

but in this query I don't want to mention 12345 but mention it as a user entered parameter like the first query :checkNum

How do I rephrase the REGEXP_LIKE condition with only 2 arguments with user input :checkNum as oracle db allows only a maximum of 2 arguments. (another problem)

1 Answer 1

1

You can concatenate the parameter:

SELECT * 
FROM BPP.CHECK_REGISTER 
WHERE REGEXP_LIKE (CHECK_NO,'^(0*'||:checkNum||')$');

Alternatively add the regex part to the user entered value (in your application code) before passing it to the query.

Sign up to request clarification or add additional context in comments.

1 Comment

how do we use the same query from JPA ?? searchCriteria.append(" and REGEXP_LIKE (e.checkNumber,'^(0*||:checkNum||)$')"); this is not a defined standard in JPA .. how do i rephrase this??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.