Best way to compare VARCHAR2 with CHAR

I am looking for the best (and fastest) way to compare VARCHAR2(50 BYTE)with CHAR(12 BYTE).

There are two databases: first contains column 1 with the CHAR column (underscore means spaces that fill the length of the CHAR)

ID  VALUE
1   123-45___
2   123-456__
3   123-457__

the second database (table2) contains VARCHAR2 without a space.

ID  VALUE
4   123-45
5   123-456
6   123-457

So I want something like this

SELECT table1.ID FROM table1 WHERE table1.VALUE = '123-45'
+4
source share
1 answer

When a column is table1.valueindexed, you do not want to manipulate it for comparison, as this will prevent the use of the index. Therefore, you need to change the value you are looking for:

SELECT table1.ID FROM table1 WHERE table1.VALUE = RPAD('123-45', 12)

Oracle , , - . , , , , :

SELECT table1.ID, table2.ID
FROM table1
JOIN table2 ON table2.value = RTRIM(table1.value)
WHERE table1.VALUE = RPAD('123-45', 12)

:

SELECT table1.ID
FROM table2
JOIN table1 ON table1.value = RPAD(table2.value, 12)
+4

Source: https://habr.com/ru/post/1536593/


All Articles