Best way to compare VARCHAR2 with CHAR

Deadly 提交于 2019-12-05 13:15:23

As the table1.value column is indexed, you don't want to manipulate that for the comparison as that would prevent the index being used. So you'll need to modify the value you're looking up:

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

Oracle will do that implicitly with the query you showed though, and will still use the index. And the same if you're joining the tables, but whether you pad or trim during the join depends on which table is the driver:

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

Or:

SELECT table1.ID
FROM table2
JOIN table1 ON table1.value = RPAD(table2.value, 12)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!