0

I have table with two VARCHAR2 columns:

trs_no trs_name
------ --------
JV1    ddd
 .      .
 .      .
 .      .
JV580  deee

I want to select for example all trs_no between JV280 and JV320

I tried the normal between but didn't work because I found JV29 in the results

So I tried also to get the length of the JV280 and JV320 in between it worked but it failed when the length is different.

How can I fix this ??

1 Answer 1

2

Split the trs_no into a two-character string prefix and the numeric postfix and compare them seperately:

SELECT *
FROM   your_table
WHERE  SUBSTR( trs_no, 1, 2 ) = 'JV'
AND    TO_NUMBER( SUBSTR( trs_no, 3 ) ) BETWEEN 280 AND 320

If trs_no can have different sized string prefixes then you could use a regular expression:

SELECT *
FROM   your_table
WHERE  REGEXP_SUBSTR( trs_no, '^(\D+)(\d+)$', 1, 1, NULL, 1 ) = 'JV'
AND    TO_NUMBER( REGEXP_SUBSTR( trs_no, '^(\D+)(\d+)$', 1, 1, NULL, 2 ) )
         BETWEEN 280 AND 320;
Sign up to request clarification or add additional context in comments.

2 Comments

Is there any way more easier ?
@AbdelrhmanHesham You could add couple of virtual columns to the table and then just select from them in the form.

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.