Oracle(旧?)连接 - 用于转换的工具/脚本?
我一直在移植 oracle selects,并且运行过很多查询,如下所示:
SELECT e.last_name,
d.department_name
FROM employees e,
departments d
WHERE e.department_id(+) = d.department_id;
...并且:
SELECT last_name,
d.department_id
FROM employees e,
departments d
WHERE e.department_id = d.department_id(+);
是否有任何指南/教程用于转换 (+) 语法的所有变体?该语法甚至被称为什么(这样我就可以搜索谷歌)?
更好..是否有一个工具/脚本可以为我进行此转换(首选免费)?某种优化器?我有大约 500 个要移植的查询。
这个标准何时被淘汰?任何信息表示赞赏。
I have been porting oracle selects, and I have been running across a lot of queries like so:
SELECT e.last_name,
d.department_name
FROM employees e,
departments d
WHERE e.department_id(+) = d.department_id;
...and:
SELECT last_name,
d.department_id
FROM employees e,
departments d
WHERE e.department_id = d.department_id(+);
Are there any guides/tutorials for converting all of the variants of the (+) syntax? What is that syntax even called (so I can scour google)?
Even better.. Is there a tool/script that will do this conversion for me (Preferred Free)? An optimizer of some sort? I have around 500 of these queries to port..
When was this standard phased out? Any info is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
(+)
是 Oracle 特定于 ANSI-92 之前的 OUTER JOIN 语法,因为 ANSI-89 语法不提供OUTER JOIN
支持的语法。是
RIGHT
还是LEFT
由哪个表&决定。附有符号的列引用。如果它在与FROM
子句中的第一个表关联的列旁边指定 - 它是RIGHT
连接。否则,它是LEFT
连接。 对于任何需要了解的人来说这是一个很好的参考JOIN 之间的区别。使用 ANSI-92 语法重写的第一个查询:
使用 ANSI-92 语法重写的第二个查询:
The
(+)
is Oracle specific pre-ANSI-92 OUTER JOIN syntax, because ANSI-89 syntax doesn't provide syntax forOUTER JOIN
support.Whether it is
RIGHT
orLEFT
is determined by which table & column reference the notation is attached to. If it is specified next to a column associated with the first table in theFROM
clause - it's aRIGHT
join. Otherwise, it's aLEFT
join. This a good reference for anyone needing to know the difference between JOINs.First query re-written using ANSI-92 syntax:
Second query re-written using ANSI-92 syntax:
谷歌“Oracle 连接语法”。
(+)
用于不同风格的外连接。我认为您展示的第一个是左外连接,第二个是右外连接。我已经有一段时间没有看到这个符号了,所以我可能有点偏离,但希望这能给你足够的信息来谷歌并得到正确的答案。更新:
那么您想要一个工具来为您完成这项工作吗?我听说 SwisSQL 可以做这样的事情,但是如果大多数查询足够简单,您可能可以编写一个小脚本来为您完成它。 OMG Ponies 的答案很好地展示了从旧语法转换为新语法的模式。
Google "Oracle join syntax". the
(+)
is used for different flavours of outer joins. I think the first one you showed is a Left Outer Join, and the second one is a Right Outer Join. I haven't seen this notation for quite a while, so I could be a little off, but hopefully, this gives you enough info to hit Google and get the right answer.UPDATE:
So you wants a tool to do it for you? I have heard that SwisSQL can do something like this, but if most of the queries are simple enough you can probably write a little script that does it for you. OMG Ponies answer nicely shows the pattern for converting from old to new syntax.
这可能会变得非常复杂,因为即使在简单的情况下,WHERE 子句
也会转换为 UNION 或子选择查询。
如果你喜欢 python,你可以看看 sqlparse,它看起来很有前途,你可能会让它执行您需要的操作,并重新格式化 SQL 代码。它可以轻松地直接在源上工作。您必须告诉它要做什么,但它确实可以让您免于编写无聊的解析部分。
This can get quite complicated as the WHERE clause in even simple situations such as
will translate to UNION or subselect query.
If you like python you might take a look at sqlparse, it looks promising and you might get it to do what you need plus some reformatting of the SQL code. It would easily work directly on the source. You'll have to tell it what to do but it does relieve you of writing the boring parsing part.
对于 Oracle 10g
http://download.oracle .com/docs/cd/B19306_01/server.102/b14200/queries006.htm#i2054012
如果您的版本不同,您可以在线找到其他版本的oracle手册,尽管连接语法可能没有不同。
For Oracle 10g
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm#i2054012
You can find the other versions of oracle manuals online if your version is different, though the join syntax is probably not different.
我似乎记得这种语法在从 Oracle 8i 到 9i 的过渡中消失了——我认为我们有一个 toad 插件,它最终为我们转换了所有内容,这样我们就不必浪费时间来完成每个查询
I seem to remember this syntax going away in the transition from Oracle 8i to 9i -- I think we had a toad plugin that ended up converting everything for us just so we didn't have to waste time going through every query
我不知道有什么工具可以自动进行转换,但即使有,您也想逐一查看其更改。因此,我认为工具不会为您节省很多时间。
http://www.dba-oracle.com/oracle_news/2004_2_19_rittman.htm 说:
此外,您不必在任何地方都使用一种风格或另一种风格。您可以一次将代码转换为一个查询,并在一定程度上保证它们都将继续工作。我将保留查询不变,并决定在新代码中使用 ANSI SQL-92 语法。
I don't know of a tool to do the conversion automatically, but even if there were, you would want to review its changes one a case by case basis anyway. Therefore, I don't think a tool would save you much time.
http://www.dba-oracle.com/oracle_news/2004_2_19_rittman.htm says:
Also you don't have to use one style or the other everywhere. You can convert your code one query at a time, with some assurance that they will all keep working. I would leave the queries as they are, and resolve to use ANSI SQL-92 syntax in new code.