Oracle(旧?)连接 - 用于转换的工具/脚本?

发布于 2024-08-25 03:49:31 字数 537 浏览 6 评论 0原文

我一直在移植 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

╭ゆ眷念 2024-09-01 03:49:31

(+) 是 Oracle 特定于 ANSI-92 之前的 OUTER JOIN 语法,因为 ANSI-89 语法不提供 OUTER JOIN 支持的语法。

RIGHT还是LEFT由哪个表&决定。附有符号的列引用。如果它在与 FROM 子句中的第一个表关联的列旁边指定 - 它是 RIGHT 连接。否则,它是LEFT 连接。 对于任何需要了解的人来说这是一个很好的参考JOIN 之间的区别

使用 ANSI-92 语法重写的第一个查询:

    SELECT e.lastname,
           d.department_name
      FROM EMPLOYEES e
RIGHT JOIN DEPARTMENTS d ON d.departmentid = e.departmentid

使用 ANSI-92 语法重写的第二个查询:

   SELECT e.lastname,
          d.department_name
     FROM EMPLOYEES e
LEFT JOIN DEPARTMENTS d ON d.departmentid = e.departmentid

The (+) is Oracle specific pre-ANSI-92 OUTER JOIN syntax, because ANSI-89 syntax doesn't provide syntax for OUTER JOIN support.

Whether it is RIGHT or LEFT 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 the FROM clause - it's a RIGHT join. Otherwise, it's a LEFT join. This a good reference for anyone needing to know the difference between JOINs.

First query re-written using ANSI-92 syntax:

    SELECT e.lastname,
           d.department_name
      FROM EMPLOYEES e
RIGHT JOIN DEPARTMENTS d ON d.departmentid = e.departmentid

Second query re-written using ANSI-92 syntax:

   SELECT e.lastname,
          d.department_name
     FROM EMPLOYEES e
LEFT JOIN DEPARTMENTS d ON d.departmentid = e.departmentid
夜清冷一曲。 2024-09-01 03:49:31

谷歌“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.

幸福不弃 2024-09-01 03:49:31

这可能会变得非常复杂,因为即使在简单的情况下,WHERE 子句

WHERE e.id = d.manager_id(+) OR e.id = d.contact_id(+)

也会转换为 UNION 或子选择查询。

如果你喜欢 python,你可以看看 sqlparse,它看起来很有前途,你可能会让它执行您需要的操作,并重新格式化 SQL 代码。它可以轻松地直接在源上工作。您必须告诉它要做什么,但它确实可以让您免于编写无聊的解析部分。

This can get quite complicated as the WHERE clause in even simple situations such as

WHERE e.id = d.manager_id(+) OR e.id = d.contact_id(+)

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.

泪痕残 2024-09-01 03:49:31

对于 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.

梦境 2024-09-01 03:49:31

我似乎记得这种语法在从 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

回心转意 2024-09-01 03:49:31

我不知道有什么工具可以自动进行转换,但即使有,您也想逐一查看其更改。因此,我认为工具不会为您节省很多时间。

http://www.dba-oracle.com/oracle_news/2004_2_19_rittman.htm 说:

与传统连接相比,使用 ANSI 连接不会带来任何性能优势或影响,但通过使用 ANSI 连接,您的查询在 DBMS 平台之间更加可移植,并且更易于阅读。不过,最终还是取决于个人喜好,虽然 ANSI 标准有其优点,但如果您不想,也无需进行切换。

此外,您不必在任何地方都使用一种风格或另一种风格。您可以一次将代码转换为一个查询,并在一定程度上保证它们都将继续工作。我将保留查询不变,并决定在新代码中使用 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:

There's no performance benefit or hit by using ANSI joins rather than traditional joins, but by using ANSI joins, your queries are more portable between DBMS platforms, and they're a bit easier to read. In the end, though, it's down to personal preference and whilst there's advantages to the ANSI standard, there's no need to switch if you don't want to.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文