在Oracle SQL中,何時需要使用分號和斜杠?本周,我們在我的公司就如何編寫SQL腳本進行了一些討論。背景:我們的數據庫是Oracle 10g(升級到11很快)。我們的DBA團隊使用SQLPlus來將腳本部署到生產中?,F在,我們最近的部署失敗了,因為它同時使用了分號和正斜杠(/)。分號在每個語句的末尾,斜杠在語句之間。alter table foo.bar drop constraint bar1;/alter table foo.can drop constraint can1;/后面在腳本中添加了一些觸發器,創建了一些視圖以及一些存儲過程。同時擁有;而/導致每個語句運行兩次,導致錯誤(特別是在需要唯一的插入上)。在SQLDeveloper中,這種情況不會發生,在TOAD中則不會發生。如果運行某些命令,則沒有/在他們身上。在PL/SQL中,如果您有一個子程序(聲明、開始、結束),所使用的分號將被視為子程序的一部分,因此必須使用斜杠。所以我的問題是:如果您的數據庫是Oracle,那么編寫SQL腳本的正確方法是什么?因為您知道您的DB是Oracle,所以應該始終使用/?
3 回答

溫溫醬
TA貢獻1752條經驗 獲得超4個贊

慕容森
TA貢獻1853條經驗 獲得超18個贊
/
;
;
/
;
和 a /
/
SQL*Plus: Release 11.2.0.1.0 Production on Wed Apr 18 12:37:20 2012Copyright (c) 1982, 2010, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - ProductionWith the Partitioning and OLAP options SQL> drop table foo;Table dropped.SQL> /drop table foo *ERROR at line 1:ORA-00942: table or view does not exist
drop table foo;/
SQL*Plus: Release 11.2.0.1.0 Production on Wed Apr 18 12:38:05 2012Copyright (c) 1982, 2010, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - ProductionWith the Partitioning and OLAP options SQL> @dropTable dropped.drop table foo *ERROR at line 1:ORA-00942: table or view does not exist
/
;
CREATE PROCEDURE
添加回答
舉報
0/150
提交
取消