Oracle 外连接简写带上
有效:
AND UPPER(a.name) = b.lname(+)
无效
AND UPPER(a.name) = UPPER(b.lname) (+)
迁移到 ANSI 连接是一种选择,但却是一项艰苦的选择。这段代码有很多地方需要修改,并且有很多连接。我想让这个语法正确并继续前进。
是否可以?
Works:
AND UPPER(a.name) = b.lname(+)
does not work
AND UPPER(a.name) = UPPER(b.lname) (+)
Moving to ANSI joins is an option but a painstaking one. This code should be changed in lot of places and there are lot of joins. I would like to get this syntax correct and be on my way.
Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
撇开恶心不谈,将 UPPER() 与旧的 skool OUTER JOIN 语法合并本身很简单:我们只需要以正确的顺序获取括号:
以下是如何使用多个表部署新语法:
Yuckiness aside, incorporating UPPER() with the old skool OUTER JOIN syntax is simplicity itself: we just need to get the brackets in the right order:
Here is how to deploy the newer syntax with multiple tables:
第二个版本的代码很可能永远无法工作。如果之前没有使用过,那么它就更可能不起作用。(有关如何使用过时的符号,请参阅已接受的答案。我仍然认为下面的其余建议仍然有效- 但请仔细注意限定符“当您需要修改 SQL 时”;如果您因其他原因不需要更改 SQL,则无需删除旧式表示法。)当您需要进行不区分大小写的比较时,硬着头皮处理 ANSI 连接。或者研究基于区域设置的替代方案(不区分大小写的比较)(如果 Oracle 中存在这样的选项)。
但从根本上来说,您应该将旧的“(+)”外连接符号扔进垃圾桶。当您必须修改 SQL 语句时,请删除旧的(过时的)表示法并使用 ANSI 连接表示法。
有评论问“如何将其转换为 ANSI”?
您重写 FROM 子句以及 WHERE 子句 - 通常将连接条件从 WHERE 子句移至 FROM 子句中的 ON 条件。
另一个评论问“如何将联接扩展到三个表”?
It is quite possible that the second version of the code will not work, ever. If it wasn't in use before, it is all the more plausible that it won't work.(See the accepted answer for how to use the obsolesent notation. I still think that the rest of the advice below stands - but note carefully the qualifier 'when you need to modify the SQL'; if you don't need to change the SQL for some other reason, there's no necessity to remove the old-style notation.)Bite the bullet and deal with the ANSI join when you need to do the case-insensitive comparison. Or investigate a locale-based alternative (with case-insensitive comparisons), if such an option exists in Oracle.
Fundamentally, though, you should consign the old '(+)' outer join notation to the trash can. When you have to modify an SQL statement, remove the old (obsolescent) notation and use the ANSI join notation instead.
A comment asks 'how can this be converted to ANSI'?
You rewrite the FROM clause as well as the WHERE clause - often moving join conditions from the WHERE clause to the ON conditions in the FROM clause.
Another comment asks 'how to extend the join to three tables'?
作品。我测试过。它运行良好。
Works. I tested it. It is working fine.