Microsoft T-SQL到Oracle PL / SQL转换

时间:2022-08-06 00:37:51

I've worked with T-SQL for years but i've just moved to an organisation that is going to require writing some Oracle stuff, probably just simple CRUD operations at least until I find my feet. I'm not going to be migrating databases from one to the other simply interacting with existing Oracle databases from an Application Development perspective. Is there are tool or utility available to easily translate T-SQL into PL/SQL, a keyword mapper is the sort of thing I'm looking for.

我已经使用过T-SQL多年了,但我刚刚搬到一个需要编写一些Oracle东西的组织,可能只是简单的CRUD操作,至少在我找到我的脚之前。我不打算将数据库从一个数据库迁移到另一个数据库,只是从应用程序开发的角度与现有的Oracle数据库进行交互。是否有工具或实用程序可以轻松地将T-SQL转换为PL / SQL,关键字映射器就是我正在寻找的东西。

P.S. I'm too lazy to RTFM, besides it's not going to be a big part of my role so I just want something to get me up to speed a little faster.

附:我对RTFM太懒了,除了它不会成为我角色的重要部分所以我只想要一些东西让我加快速度。

11 个解决方案

#1


18  

The language difference listed so far are trivial compared to the logical differences. Anyone can lookup NVL. What's hard to lookup is

到目前为止列出的语言差异与逻辑差异相比是微不足道的。任何人都可以查找NVL。什么难以查找

DDL

DDL

In SQL server you manipulate your schema, anywhere, anytime, with little or no fuss.

在SQL服务器中,您可以随时随地操纵架构,几乎不用担心。

In Oracle, we don't like DDL in stored procedures so you have jump through hoops. You need to use EXECUTE IMMEDIATE to perform a DDL function.

在Oracle中,我们不喜欢存储过程中的DDL,所以你已经跳过了箍。您需要使用EXECUTE IMMEDIATE来执行DDL功能。

Temp Tables

临时表

IN SQL Server when the logic becomes a bit tough, the common thing is to shortcut the sql and have it resolved to a temp table and then the next step is done using that temp table. MSSS makes it very easy to do this.

在SQL Server中,当逻辑变得有点困难时,常见的是快速执行sql并将其解析为临时表,然后使用该临时表完成下一步。 MSSS使这很容易实现。

In Oracle we don't like that. By forcing an intermediate result you completely prevent the Optimizer from finding a shortcut for you. BUT If you must stop halfway and persist the intermediate results Oracle wants you to make the temp table in advance, not on the fly.

在Oracle中我们不喜欢这样。通过强制中间结果,您可以完全阻止优化程序为您找到快捷方式。但是如果你必须中途停止并坚持中间结果,Oracle希望你提前制作临时表,而不是动态。

Locks

In MSSS you worry about locking, you have nolock hints to apply to DML, you have lock escalation to reduce the count of locks.

在MSSS中你担心锁定,你有nolock提示要应用于DML,你有锁升级以减少锁的数量。

In Oracle we don't worry about these in that way.

在Oracle中,我们不会以这种方式担心这些问题。

Read Commited

阅读Commited

Until recently MSSS didn't fully handle Read Committed isolation so you worried about dirty reads.

直到最近,MSSS还没有完全处理Read Committed隔离,所以你担心脏读。

Oracle has been that way for decades.

Oracle几十年来一直如此。

etc

等等

MSSS has no concept of Bitmap indexes, IOT, Table Clusters, Single Table hash clusters, non unique indexes enforcing unique constraints....

MSSS没有Bitmap索引,IOT,表集群,单表散列集群,非唯一索引强制执行唯一约束的概念....

#2


14  

I get the impression most answers focus on migrating an entire database or just point to some differences between T-SQL and PL/SQL. I recently had the same problem. The Oracle database exists, but I need to convert a whole load of T-SQL scripts to PL/SQL.

我得到的印象是大多数答案都集中在迁移整个数据库或只是指出T-SQL和PL / SQL之间的一些差异。我最近遇到了同样的问题。 Oracle数据库存在,但我需要将整个T-SQL脚本转换为PL / SQL。

I installed Oracle SQL Developer and ran the Translation Scratch Editor (Tools > Migration > Translation Scratch Editor).

我安装了Oracle SQL Developer并运行了Translation Scratch Editor(工具>迁移> Translation Scratch Editor)。

Then, just enter your T-SQL, choose the correct translation in the dropdownlist (it should default to 'T-SQL to PL/SQL'), and convert it.

然后,只需输入您的T-SQL,在下拉列表中选择正确的翻译(它应默认为'T-SQL to PL / SQL'),然后进行转换。

#3


4  

I have to things to mention.

我不得不提一提。

1) When I worked on Oracle 8, you could not do "Select @Result", you had to instead use the dummy table as follows "Select @Result from dual". Not sure if that ridiculousness still exists.

1)当我使用Oracle 8时,你不能做“选择@Result”,你必须使用虚拟表,如下所示“从双重选择@Result”。不确定这种荒谬是否仍然存在。

2) In the Oracle world they seem to love cursors and you better read up on them, they use them all the time AFAICS.

2)在Oracle世界中,他们似乎喜欢游标,你最好阅读它们,他们一直使用它们AFAICS。

Good luck and enjoy,

祝你好运,享受,

it is not that different to MS SQL. Thankfully, I do not have to work with it anymore and I am back in the warm comfort of MS tools.

它与MS SQL没有什么不同。值得庆幸的是,我不再需要使用它了,我又回到了MS工具的温暖舒适状态。

#4


2  

If you replace your ISNULL and NVL nonsense with COALESCE, it'll work in T-SQL and PL/SQL!

如果用COALESCE替换你的ISNULL和NVL废话,它将在T-SQL和PL / SQL中工作!

#5


2  

The most important differences for plain T-SQL are:

普通T-SQL最重要的区别是:

  • NVL replaces ISNULL
  • NVL取代了ISNULL
  • SYSDATE replaces GETDATE()
  • SYSDATE替换GETDATE()
  • CONVERT is not supported
  • 不支持CONVERT
  • Identity columns must be replaced with sequences <-- not technically T- or PL/ but just SQL
  • 标识列必须用序列替换< - 技术上不是T-或PL /,而只是SQL

Note. I assume you do not use the deprecated SQL Server *= syntax for joins

注意。我假设您不使用已弃用的SQL Server * =语法进行连接

@jodonell: The table you link to is a bit outdated, oracle has become somewhat more standards compliant after 9i supporting things like CASE and ANSI outer joins

@jodonell:你链接到的表有点过时,在9i支持诸如CASE和ANSI外连接之类的东西后,oracle变得更加符合标准

#6


1  

It's not trivial to map them back and forth, so I doubt there's a tool that does it automatically. But this link might help you out: http://vyaskn.tripod.com/oracle_sql_server_differences_equivalents.htm

来回映射它们并非易事,所以我怀疑是否有一个自动完成它的工具。但是这个链接可能会帮到你:http://vyaskn.tripod.com/oracle_sql_server_differences_equivalents.htm

#7


1  

I have done a few SQL server to oracle migrations. There is no way to migrate without rewriting the backend code. Too many differences between the 2 databases and more importantly differences between the 2 mind sets of the programmers. Many managers think that the 2 are interchangeable, I have had managers ask me to copy the stored procedures from SQL server and compile them in oracle, not a clue! Toad is by far the best tool on the market for supporting an oracle application. SQL developer is ok but was disappointing compared to toad. I hope that oracle will catch their product up to toad one day but it is not there yet. Have a good day :) chances are if you are migrating to oracle it is for a reason and in order to meet that requirement you will need to rewrite the back end code or you will have many issues.

我已经为oracle迁移做了一些SQL服务器。没有重写后端代码就无法迁移。两个数据库之间的差异太大,更重要的是程序员的两个思维集之间的差异。许多经理认为2是可以互换的,我有经理要求我从SQL服务器复制存储过程并在oracle中编译它们,而不是线索! Toad是目前市场上支持oracle应用程序的最佳工具。 SQL开发人员还可以,但与toad相比令人失望。我希望甲骨文有一天会把他们的产品赶上蟾蜍,但它还没有。祝你有个美好的一天:)如果你正在迁移到oracle,这是有原因的,为了满足这个要求,你需要重写后端代码,否则你会遇到很多问题。

#8


1  

In Oracle SQL Developer, there is a tool called Translation Scratch Editor. You can find it from Tools > Migration.

在Oracle SQL Developer中,有一个名为Translation Scratch Editor的工具。您可以从工具>迁移中找到它。

The Oracle SQL Developer is a free download from Oracle and it is an easy install.

Oracle SQL Developer可以从Oracle免费下载,安装简单。

#9


0  

If you're doing a one-off conversion, rather than trying to support two versions, you must look at Oracle Migration Workbench. This tool works with Oracle's SQLDeveloper (which you really should have if you are working with Oracle). This does a conversion of the schema, data, and some of the T-SQL to PL/SQL. Knowing both well, I found it did about an 80% job. Good enough to make it worth while to convert the bulk of procedures, and hand convert the remainder "tougher" unknown parts.

如果您正在进行一次性转换,而不是尝试支持两个版本,则必须查看Oracle Migration Workbench。此工具适用于Oracle的SQLDeveloper(如果您使用的是Oracle,那么您应该使用它)。这样可以将模式,数据和一些T-SQL转换为PL / SQL。知道得很好,我发现它做了大约80%的工作。足够好以使转换大量程序,并手动转换其余“更强硬”的未知部分值得。

#10


0  

Not cheap ($995) but this tool works great: http://www.swissql.com/products/sql-translator/sql-converter.html

不便宜(995美元),但这个工具很棒:http://www.swissql.com/products/sql-translator/sql-converter.html

#11


0  

A few people have mentioned here converting back and forward. I do not know of a tool to convert from MSSQL to Oracle, but I used the free MS tool to convert a Oracle db to MSSQL and it worked for me and converted a large db with no problems I can call. It is similar to the Access to MSSQL tool that MS also provide for free. Enjoy

这里有一些人提到了前后转换。我不知道从MSSQL转换到Oracle的工具,但是我使用免费的MS工具将Oracle数据库转换为MSSQL,它对我有用并转换了一个大型数据库而没有我可以调用的问题。它类似于MS也免费提供的Access to MSSQL工具。请享用

#1


18  

The language difference listed so far are trivial compared to the logical differences. Anyone can lookup NVL. What's hard to lookup is

到目前为止列出的语言差异与逻辑差异相比是微不足道的。任何人都可以查找NVL。什么难以查找

DDL

DDL

In SQL server you manipulate your schema, anywhere, anytime, with little or no fuss.

在SQL服务器中,您可以随时随地操纵架构,几乎不用担心。

In Oracle, we don't like DDL in stored procedures so you have jump through hoops. You need to use EXECUTE IMMEDIATE to perform a DDL function.

在Oracle中,我们不喜欢存储过程中的DDL,所以你已经跳过了箍。您需要使用EXECUTE IMMEDIATE来执行DDL功能。

Temp Tables

临时表

IN SQL Server when the logic becomes a bit tough, the common thing is to shortcut the sql and have it resolved to a temp table and then the next step is done using that temp table. MSSS makes it very easy to do this.

在SQL Server中,当逻辑变得有点困难时,常见的是快速执行sql并将其解析为临时表,然后使用该临时表完成下一步。 MSSS使这很容易实现。

In Oracle we don't like that. By forcing an intermediate result you completely prevent the Optimizer from finding a shortcut for you. BUT If you must stop halfway and persist the intermediate results Oracle wants you to make the temp table in advance, not on the fly.

在Oracle中我们不喜欢这样。通过强制中间结果,您可以完全阻止优化程序为您找到快捷方式。但是如果你必须中途停止并坚持中间结果,Oracle希望你提前制作临时表,而不是动态。

Locks

In MSSS you worry about locking, you have nolock hints to apply to DML, you have lock escalation to reduce the count of locks.

在MSSS中你担心锁定,你有nolock提示要应用于DML,你有锁升级以减少锁的数量。

In Oracle we don't worry about these in that way.

在Oracle中,我们不会以这种方式担心这些问题。

Read Commited

阅读Commited

Until recently MSSS didn't fully handle Read Committed isolation so you worried about dirty reads.

直到最近,MSSS还没有完全处理Read Committed隔离,所以你担心脏读。

Oracle has been that way for decades.

Oracle几十年来一直如此。

etc

等等

MSSS has no concept of Bitmap indexes, IOT, Table Clusters, Single Table hash clusters, non unique indexes enforcing unique constraints....

MSSS没有Bitmap索引,IOT,表集群,单表散列集群,非唯一索引强制执行唯一约束的概念....

#2


14  

I get the impression most answers focus on migrating an entire database or just point to some differences between T-SQL and PL/SQL. I recently had the same problem. The Oracle database exists, but I need to convert a whole load of T-SQL scripts to PL/SQL.

我得到的印象是大多数答案都集中在迁移整个数据库或只是指出T-SQL和PL / SQL之间的一些差异。我最近遇到了同样的问题。 Oracle数据库存在,但我需要将整个T-SQL脚本转换为PL / SQL。

I installed Oracle SQL Developer and ran the Translation Scratch Editor (Tools > Migration > Translation Scratch Editor).

我安装了Oracle SQL Developer并运行了Translation Scratch Editor(工具>迁移> Translation Scratch Editor)。

Then, just enter your T-SQL, choose the correct translation in the dropdownlist (it should default to 'T-SQL to PL/SQL'), and convert it.

然后,只需输入您的T-SQL,在下拉列表中选择正确的翻译(它应默认为'T-SQL to PL / SQL'),然后进行转换。

#3


4  

I have to things to mention.

我不得不提一提。

1) When I worked on Oracle 8, you could not do "Select @Result", you had to instead use the dummy table as follows "Select @Result from dual". Not sure if that ridiculousness still exists.

1)当我使用Oracle 8时,你不能做“选择@Result”,你必须使用虚拟表,如下所示“从双重选择@Result”。不确定这种荒谬是否仍然存在。

2) In the Oracle world they seem to love cursors and you better read up on them, they use them all the time AFAICS.

2)在Oracle世界中,他们似乎喜欢游标,你最好阅读它们,他们一直使用它们AFAICS。

Good luck and enjoy,

祝你好运,享受,

it is not that different to MS SQL. Thankfully, I do not have to work with it anymore and I am back in the warm comfort of MS tools.

它与MS SQL没有什么不同。值得庆幸的是,我不再需要使用它了,我又回到了MS工具的温暖舒适状态。

#4


2  

If you replace your ISNULL and NVL nonsense with COALESCE, it'll work in T-SQL and PL/SQL!

如果用COALESCE替换你的ISNULL和NVL废话,它将在T-SQL和PL / SQL中工作!

#5


2  

The most important differences for plain T-SQL are:

普通T-SQL最重要的区别是:

  • NVL replaces ISNULL
  • NVL取代了ISNULL
  • SYSDATE replaces GETDATE()
  • SYSDATE替换GETDATE()
  • CONVERT is not supported
  • 不支持CONVERT
  • Identity columns must be replaced with sequences <-- not technically T- or PL/ but just SQL
  • 标识列必须用序列替换< - 技术上不是T-或PL /,而只是SQL

Note. I assume you do not use the deprecated SQL Server *= syntax for joins

注意。我假设您不使用已弃用的SQL Server * =语法进行连接

@jodonell: The table you link to is a bit outdated, oracle has become somewhat more standards compliant after 9i supporting things like CASE and ANSI outer joins

@jodonell:你链接到的表有点过时,在9i支持诸如CASE和ANSI外连接之类的东西后,oracle变得更加符合标准

#6


1  

It's not trivial to map them back and forth, so I doubt there's a tool that does it automatically. But this link might help you out: http://vyaskn.tripod.com/oracle_sql_server_differences_equivalents.htm

来回映射它们并非易事,所以我怀疑是否有一个自动完成它的工具。但是这个链接可能会帮到你:http://vyaskn.tripod.com/oracle_sql_server_differences_equivalents.htm

#7


1  

I have done a few SQL server to oracle migrations. There is no way to migrate without rewriting the backend code. Too many differences between the 2 databases and more importantly differences between the 2 mind sets of the programmers. Many managers think that the 2 are interchangeable, I have had managers ask me to copy the stored procedures from SQL server and compile them in oracle, not a clue! Toad is by far the best tool on the market for supporting an oracle application. SQL developer is ok but was disappointing compared to toad. I hope that oracle will catch their product up to toad one day but it is not there yet. Have a good day :) chances are if you are migrating to oracle it is for a reason and in order to meet that requirement you will need to rewrite the back end code or you will have many issues.

我已经为oracle迁移做了一些SQL服务器。没有重写后端代码就无法迁移。两个数据库之间的差异太大,更重要的是程序员的两个思维集之间的差异。许多经理认为2是可以互换的,我有经理要求我从SQL服务器复制存储过程并在oracle中编译它们,而不是线索! Toad是目前市场上支持oracle应用程序的最佳工具。 SQL开发人员还可以,但与toad相比令人失望。我希望甲骨文有一天会把他们的产品赶上蟾蜍,但它还没有。祝你有个美好的一天:)如果你正在迁移到oracle,这是有原因的,为了满足这个要求,你需要重写后端代码,否则你会遇到很多问题。

#8


1  

In Oracle SQL Developer, there is a tool called Translation Scratch Editor. You can find it from Tools > Migration.

在Oracle SQL Developer中,有一个名为Translation Scratch Editor的工具。您可以从工具>迁移中找到它。

The Oracle SQL Developer is a free download from Oracle and it is an easy install.

Oracle SQL Developer可以从Oracle免费下载,安装简单。

#9


0  

If you're doing a one-off conversion, rather than trying to support two versions, you must look at Oracle Migration Workbench. This tool works with Oracle's SQLDeveloper (which you really should have if you are working with Oracle). This does a conversion of the schema, data, and some of the T-SQL to PL/SQL. Knowing both well, I found it did about an 80% job. Good enough to make it worth while to convert the bulk of procedures, and hand convert the remainder "tougher" unknown parts.

如果您正在进行一次性转换,而不是尝试支持两个版本,则必须查看Oracle Migration Workbench。此工具适用于Oracle的SQLDeveloper(如果您使用的是Oracle,那么您应该使用它)。这样可以将模式,数据和一些T-SQL转换为PL / SQL。知道得很好,我发现它做了大约80%的工作。足够好以使转换大量程序,并手动转换其余“更强硬”的未知部分值得。

#10


0  

Not cheap ($995) but this tool works great: http://www.swissql.com/products/sql-translator/sql-converter.html

不便宜(995美元),但这个工具很棒:http://www.swissql.com/products/sql-translator/sql-converter.html

#11


0  

A few people have mentioned here converting back and forward. I do not know of a tool to convert from MSSQL to Oracle, but I used the free MS tool to convert a Oracle db to MSSQL and it worked for me and converted a large db with no problems I can call. It is similar to the Access to MSSQL tool that MS also provide for free. Enjoy

这里有一些人提到了前后转换。我不知道从MSSQL转换到Oracle的工具,但是我使用免费的MS工具将Oracle数据库转换为MSSQL,它对我有用并转换了一个大型数据库而没有我可以调用的问题。它类似于MS也免费提供的Access to MSSQL工具。请享用