oracle SQL 加上如何在 SQL 文件中结束命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8406835/
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
oracle SQL plus how to end command in SQL file?
提问by JavaSheriff
I have SQL file with few commands.
What it the correct way to end lines in the script?
Is it slash [/] semicolon [;] both?
Is there any diffarent between regular sqls and Stored procedure code?
Thank you
我有几个命令的 SQL 文件。
在脚本中结束行的正确方法是什么?
它是斜线 [/] 分号 [;] 两者吗?
常规 sql 和存储过程代码之间有什么区别吗?
谢谢
回答by Dave Costa
For normal SQL statements, either a /
on a line by itself, or a ;
at the end of the command, will work fine.
对于普通的 SQL 语句,单独的/
一行或;
命令末尾的a都可以正常工作。
For statements that include PL/SQL code, such as CREATE FUNCTION
, CREATE PROCEDURE
, CREATE PACKAGE
, CREATE TYPE
, or anonymous blocks (DECLARE
/BEGIN
/END
), a ;
will not execute the command. Since PL/SQL uses semicolons as line terminators, its use as a command terminator must be suppressed in these statements. So in these cases, you must use /
to execute the command.
对于语句包括PL / SQL代码,例如CREATE FUNCTION
,CREATE PROCEDURE
,CREATE PACKAGE
,CREATE TYPE
,或匿名块(DECLARE
/ BEGIN
/ END
),一;
将不执行该命令。由于 PL/SQL 使用分号作为行终止符,因此在这些语句中必须禁止将分号用作命令终止符。所以在这些情况下,你必须使用/
来执行命令。
In my experience, people prefer to use the semicolon when possible and use the slash only when required.
根据我的经验,人们更喜欢在可能的情况下使用分号,而仅在需要时才使用斜线。
Note that for SQLPlus client commands -- such as SET
or EXECUTE
-- no command terminator is necessary at all, although people often end them with a semicolon out of habit.
请注意,对于 SQLPlus 客户端命令——例如SET
或EXECUTE
——根本不需要命令终止符,尽管人们经常出于习惯以分号结束它们。
回答by Daniel Haviv
; is the way you should end your sql commands, same goes for PLSQL procedures:
; 是您应该结束 sql 命令的方式,PLSQL 过程也是如此:
select * from dual;
select * from dual;
select sysdate from dual;
select sysdate from dual;
select table_name from user tables;
select table_name from user tables;
exec dbms_output.putline('Hello');
exec dbms_output.putline('Hello');
回答by madhavan
Usually we can use ";
" to end sql statement,
but for create functions
, triggers
, procedures
you have to use "/
" after ";
" to end SQL statement.
"/
" might not be required when you use some developers tool like, oracle SQL developer, toad etc, but it should be mandate when you execute your query directly in the linux machine.
通常我们可以使用“ ;
”来结束sql语句,
但是对于create functions
, triggers
,则procedures
必须在“ /
”之后使用“ ;
”来结束SQL语句。当您使用某些开发人员工具(如 oracle SQL developer、toad 等)时,可能不需要
“ /
”,但是当您直接在 linux 机器上执行查询时,它应该是必需的。