oracle SQL plus如何结束SQL文件中的命令?
我有包含很少命令的 SQL 文件。
脚本中结束行的正确方法是什么?
是斜线[/]分号[;]两者吗?
常规sql和存储过程代码有什么不同吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于普通的 SQL 语句,单独一行中的
/
或命令末尾的;
都可以正常工作。对于包含 PL/SQL 代码的语句,例如
CREATE FUNCTION
、CREATE PROCEDURE
、CREATE PACKAGE
、CREATE TYPE
或匿名块(DECLARE
/BEGIN
/END
),;
将不会执行该命令。由于 PL/SQL 使用分号作为行终止符,因此在这些语句中必须禁止将分号用作命令终止符。因此在这些情况下,您必须使用/
来执行命令。根据我的经验,人们更喜欢在可能的情况下使用分号,并且仅在需要时才使用斜杠。
请注意,对于 SQLPlus 客户端命令(例如
SET
或EXECUTE
),根本不需要命令终止符,尽管人们经常出于习惯以分号结束它们。For normal SQL statements, either a
/
on a line by itself, or a;
at the end of the command, will work fine.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.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
orEXECUTE
-- no command terminator is necessary at all, although people often end them with a semicolon out of habit.;是结束 sql 命令的方式,PLSQL 过程也是如此:
select * from Dual;
select sysdate from Dual;
select table_name from user rows;< /code>
exec dbms_output.putline('Hello');
; is the way you should end your sql commands, same goes for PLSQL procedures:
select * from dual;
select sysdate from dual;
select table_name from user tables;
exec dbms_output.putline('Hello');
通常我们可以使用“
;
”来结束sql语句,但对于创建
函数
、触发器
、过程
,您必须在“;<之后使用”
/
” /code>" 结束 SQL 语句。当您使用某些开发工具(例如,oracle SQL Developer、toad 等)时,可能不需要“
/
”,但当您直接在 Linux 计算机中执行查询时,它应该是必需的。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.