在 Oracle SQL 语句中使用分号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/860378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:14:46  来源:igfitidea点击:

Using Semicolons in Oracle SQL Statements

sqlperformanceoracle

提问by Kevin Babcock

Disclaimer: I just started work on a new contract, which forced me to switch from MSSQL to Oracle. So I am a complete newcomer to Oracle and probably bring many bad MSSQL practices with me. Okay, on to the question...

免责声明:我刚刚开始处理一份新合同,这迫使我从 MSSQL 切换到 Oracle。所以我完全是 Oracle 的新手,可能带来了许多不好的 MSSQL 实践。好的,进入问题...

According to an answer in this thread, semicolons are bad and should be avoided. I realized this firsthand after spending hours trying to figure out why my queries were running so terribly slow in SQL Developer. After removing the semicolon from the end of a complex query, it finished in a matter of seconds (compared to me just giving up on it after several minutes, which was the case before removing the semicolon). This behavior startled me, and a Google search didn't turn up much as to when and why I should or should not use semicolons in my SQL statements. Can anyone clear this up with a brief explanation?

根据此线程中的答案,分号是不好的,应避免使用。在花了几个小时试图弄清楚为什么我的查询在 SQL Developer 中运行得如此缓慢之后,我第一手意识到了这一点。从复杂查询的末尾删除分号后,它在几秒钟内完成(与我在几分钟后放弃它相比,这是删除分号之前的情况)。这种行为让我感到震惊,Google 搜索并没有发现我何时以及为什么应该或不应该在我的 SQL 语句中使用分号。任何人都可以通过简短的解释来澄清这一点吗?

And if you have any links to online resources for poor developers moving from MSSQL to Oracle, then I'd greatly appreciate it!

如果您有任何指向从 MSSQL 迁移到 Oracle 的贫穷开发人员的在线资源链接,我将不胜感激!

Thanks!

谢谢!

回答by Andy Lester

It's not the semicolon. Rerunning the same query meant that the rows were already cached, so you got them back much faster.

这不是分号。重新运行相同的查询意味着行已经被缓存,所以你可以更快地恢复它们。

回答by Irfan Mulic

I am coming from 5+ years of MS SQL Experience and 4+ years of Oracle Development. I know you will hate a lot of Oracle features, especially in SQL, ;) but take it easy. Oracle is a really powerful DBMS. Even though from lot of perspectives I prefer MSSQL over Oracle but that's a different topic.

我拥有 5 年以上的 MS SQL 经验和 4 年以上的 Oracle 开发经验。我知道您会讨厌 Oracle 的许多特性,尤其是 SQL 中的特性,;) 但请放轻松。Oracle 是一个非常强大的 DBMS。尽管从很多角度来看,我更喜欢 MSSQL 而不是 Oracle,但这是一个不同的话题。

As for your issue:

至于你的问题:

A semicolon is just a statement separator.

分号只是一个语句分隔符。

SQL developer is using Java and OCI so you might have different issues (I am just guessing something can be wrong).

SQL 开发人员正在使用 Java 和 OCI,因此您可能会遇到不同的问题(我只是猜测可能有问题)。

If you feel something is not running right I advise you to get that query and run it in SQLPLUS instead of Visual Query Tools because it will give you the right feeling.

如果您觉得某些东西运行不正确,我建议您获取该查询并在 SQLPLUS 中运行它,而不是在 Visual Query Tools 中运行它,因为它会给您正确的感觉。

Good luck with Oracle development.

祝 Oracle 开发顺利。

Visit SQL*Plus FAQ.

访问SQL*Plus 常见问题解答

回答by HLGEM

Here is a book that will help tremendously SQL in a Nutshell by Kevin and Daniel Kline

这是 Kevin 和 Daniel Kline 合着的一本书,它将极大地帮助 SQL in a Nutshell

This has the syntax for both Oracle and SQl server so you can easily see how to convert things to Oracle syntax if you know how to write in t-SQL.

它具有 Oracle 和 SQl 服务器的语法,因此如果您知道如何用 t-SQL 编写,则可以轻松了解如何将内容转换为 Oracle 语法。

回答by stili

Having worked with Oracle as a developer from PowerBuilder, Java, .NET and TOAD for 10+ years this sounds strange.

作为来自 PowerBuilder、Java、.NET 和 TOAD 的开发人员与 Oracle 合作 10 多年,这听起来很奇怪。

I would suggest using explain plan to find what is happening and making sure the database is healthy, with proper statistics and indexes.

我建议使用解释计划来查找正在发生的事情并确保数据库是健康的,具有适当的统计数据和索引。

From earlier versions of Oracle I remember that using rule based optimization could lead to these kind of performance problems, but lately cost based optimization and statistics has made these kind of problems a thing of the past.

我记得在早期版本的 Oracle 中,使用基于规则的优化可能会导致此类性能问题,但最近基于成本的优化和统计使此类问题成为过去。