简体   繁体   English

将 Oracle SQL 转换为 SQL 服务器

[英]Converting Oracle SQL to SQL Server

I'm looking into converting an Oracle query into SQL Server query and I am a little confused as I want to make sure I'm understanding it correctly...我正在考虑将 Oracle 查询转换为 SQL 服务器查询,我有点困惑,因为我想确保我正确理解它......

Say I have a query..说我有一个查询..

Select t1.Name, t2.Address, t3.Num
From t1, t2, t3
Where t1.code = t2.othercode
  and t2.Id = t3.otherId
  and t3.Indicator = 'N'

Now the FROM statement - this means that they are all INNER JOINED automatically?现在是FROM语句 - 这意味着它们都是自动INNER JOINED吗? but I am not specifying what FIELDS they are joined on?但我没有具体说明他们加入了哪些FIELDS My question basically is, is the WHERE clause in Oracle what I should be JOINING on in my FROM part of the query as in:我的问题基本上是,Oracle 中的 WHERE 子句是我应该在查询的 FROM 部分中加入的内容,如下所示:

SELECT t1.Name, t2.Address, t3.Num
FROM t1 
JOIN t2 ON t1.code = t2.othercode
JOIN t3 ON t2.id = t3.otherId AND t3.indicator = 'N'

Would the above 2 queries do the same?上面的 2 个查询会做同样的事情吗?

I don't have exact data in Oracle as I do in SQL Server and I'm trying to make sure my logic is sound.我在 Oracle 中没有确切的数据,就像在 SQL 服务器中一样,我正在努力确保我的逻辑是正确的。

Thanks.谢谢。

Your join query is equivalent to the version with commas.您的join查询相当于带逗号的版本。 The queries should be functionally equivalent (return the same result set).查询在功能上应该是等效的(返回相同的结果集)。 I would actually expect them to produce the same execution plans.我实际上希望他们产生相同的执行计划。

That said, you should write the query using join in both databases.也就是说,您应该在两个数据库中使用join编写查询。 That has been the preferred syntax for more than two decades (in general: Oracle was a little late to the party).二十多年来,这一直是首选语法(通常:Oracle 有点晚了)。

And both databases should handle the query with commas -- databases do still support the archaic syntax.两个数据库都应该用逗号处理查询——数据库仍然支持古老的语法。 So, you can test the version with join in Oracle and validate that it produces the same result set.因此,您可以在 Oracle 中使用join测试版本并验证它是否产生相同的结果集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM