如何在 SQL 中连接两个字符串列时忽略尾部斜杠
我有两个表 tableA 和 tableB 如下所述
desc tableA
GUID
PROPERTY_NAME
PROPERY_VALUE
ANOTHER_COL_1
ANTHER_COL_2
desc tableB
GUID
PROPERY_NAME
PROPERTY_VALUE
RANDOM_COL_1
RANDOME_COL_2
我有以下查询来获取具有与 property_name 匹配的值的条目列表,这里是“URL”
SELECT A.GUID as SOURCE_GUID,
B.GUID as DESTINATION_GUID
FROM
tableA A,
tableB B
WHERE
A.PROPERTY_NAME = "URL" AND
A.PROPERY_NAME = B.PROPERTY_NAME AND
A.PROPERTY_VALUE = B.PROPERTY_VALUE
这里的问题是因为属性值是 URL,它们可能有也可能没有尾随削减。我希望无论尾随斜杠如何,都会发生连接。请建议一种更好的方法来实现相同的目的,而无需使用 PL/SQL 过程来删除尾部斜杠。
I have two tables tableA and tableB as described bellow
desc tableA
GUID
PROPERTY_NAME
PROPERY_VALUE
ANOTHER_COL_1
ANTHER_COL_2
desc tableB
GUID
PROPERY_NAME
PROPERTY_VALUE
RANDOM_COL_1
RANDOME_COL_2
I have the following query to fetch the list of entries which have matching values for property_name which here is "URL"
SELECT A.GUID as SOURCE_GUID,
B.GUID as DESTINATION_GUID
FROM
tableA A,
tableB B
WHERE
A.PROPERTY_NAME = "URL" AND
A.PROPERY_NAME = B.PROPERTY_NAME AND
A.PROPERTY_VALUE = B.PROPERTY_VALUE
The issue here is as propery values are URLs, they may or may not have trailing slash. I want the join to happen regardless of trailing slash. Please suggest a better way of achieving the same with out using an PL/SQL procedures to remove the trailing slash.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你有两个选择。
首先是在使用前清理数据。
在将任何 URL 存储到系统中之前,请根据需要添加或删除(根据需要)斜杠。这样可以确保所有 URL 都以相同的格式存储,以便于使用。
第二个是在运行时清理数据。
我不提倡这些选项,因为它们会产生不必要的开销,并且会妨碍索引的最佳使用。
最干净的代码,但可能会阻止索引的使用。
或...
如果其中一个条件为真,则 URL 匹配。
更混乱,但可能对索引更友好
You have two options.
The first is clean your data before use.
Before any URL is stored in the system, add or remove (as prefered) a slash if necessary. In this way ensure that all URLs are stored in the same format for ease of use.
The second is clean your data at run time.
I do not advocate these options as they incur unnecessary overheads and can prevent optimal use of indexes.
Cleanest code, but likely prevent index use.
Or...
If either of these conditions are true, the URLs match.
Much messier, but May be more index friendly
您可以使用 RTRIM 函数轻松删除尾部斜杠:
You can easily remove trailing slashes using the RTRIM function: