Oracle PL/SQL 脚本中的这个斜杠字符是错误的吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/193215/
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
Is this slash character in an Oracle PL/SQL script an error?
提问by danieltalsky
I'm sorting out a series of SQL scripts for my company written in Oracle PL/SQL. I came across an essential script with a strangely placed slash near the bottom. It is checked into CVS this way. Is this a pure syntax error or does it have some function I'm not aware of. The slightly obfuscated script:
我正在整理我公司用 Oracle PL/SQL 编写的一系列 SQL 脚本。我遇到了一个基本脚本,底部附近有一个奇怪的斜线。它以这种方式检入 CVS。这是一个纯粹的语法错误还是它有一些我不知道的功能。稍微混淆的脚本:
set serveroutput on size 2000;
--PL/SQL block to link ISSN in serial base on a company's ISSN text file
declare
cursor ItemCursor is
select issn is2 from web.obfuscated1 where issn is not null
union
select eissn is2 from web.obfuscated1 where eissn is not null;
cursor ItemCursor1(aIS varchar2) is
select obfuscated1_uid from web.obfuscated1 where group_num is null and issn in (
select distinct issn from web.obfuscated1 where issn = aIS or eissn = aIS
union
select distinct eissn from web.obfuscated1 where issn = aIS or eissn = aIS
)
union
select obfuscated1_uid from web.obfuscated1 where eissn in (
select distinct issn from web.obfuscated1 where issn = aIS or eissn = aIS
union
select distinct eissn from web.obfuscated1 where issn = aIS or eissn = aIS
);
cursor ItemCursor2(aIS9 varchar2) is
select obfuscated1_uid from web.obfuscated1 where issn in (
select distinct issn from web.obfuscated1 where issn = aIS9 or eissn = aIS9
union
select distinct eissn from web.obfuscated1 where issn = aIS9 or eissn = aIS9
) and group_num is null;
agroup number(8);
processCount number(8);
------------------------------------------------------
-- MAIN BLOCK -----------------------------------
-------------------------------------------------
begin
processCount := 0;
agroup := null;
for itemRec in ItemCursor loop
agroup := null;
begin
select group_num into agroup from web.obfuscated1 where issn in (
select distinct issn from web.obfuscated1 where issn = itemRec.is2 or eissn = itemRec.is2
union
select distinct eissn from web.obfuscated1 where issn = itemRec.is2 or eissn = itemRec.is2
) and group_num is not null and issn is not null and eissn is not null and rownum <= 1;
exception
when no_data_found then
agroup := null;
when others then
agroup := null;
end;
if agroup is not null then
for itemRec2 in ItemCursor2(itemRec.is2) loop
update web.obfuscated1 set group_num = agroup where obfuscated1_uid = itemRec2.obfuscated1_uid;
commit;
end loop;
else
processCount := processCount + 1;
for itemRec1 in ItemCursor1(itemRec.is2) loop
update web.obfuscated1 set group_num = processCount where obfuscated1_uid = itemRec1.obfuscated1_uid;
commit;
end loop;
commit;
end if;
end loop;
dbms_output.put_line('Total record read: ' || processCount);
exception
when others then
dbms_output.put_line('ORA' || sqlcode);
dbms_output.put_line(substr(sqlerrm, 1, 255));
dbms_output.put_line('ORA- Error during processing ' );
end;
/
exit;
回答by Eddie Awad
The slash has a meaning:
斜线有一个含义:
Executes the most recently executed SQL command or PL/SQL block which is stored in the SQL buffer. You can enter a slash (/) at the command prompt or at a line number prompt of a multi-line command. The slash command functions similarly to RUN, but does not list the command.
执行存储在 SQL 缓冲区中的最近执行的 SQL 命令或 PL/SQL 块。您可以在命令提示符处或多行命令的行号提示符处输入斜杠 (/)。斜线命令的功能与 RUN 类似,但不列出命令。
回答by ibre5041
When using Oracle you "mix"?three different grammars.
使用 Oracle 时,您“混合”了三种不同的语法。
- SQL
- PL/SQL
- sqlplus (command line client)
- 查询语句
- PL/SQL
- sqlplus(命令行客户端)
sqlplus can execute/process SQL?and PL/SQL?statements by sending them onto DB server. While sqlplus commands are interpreted by sqlplus itself.
sqlplus 可以通过将 SQL 和 PL/SQL 语句发送到数据库服务器来执行/处理它们。而 sqlplus 命令由 sqlplus 本身解释。
The semicolon ";"?is not part of the SQL?grammar and sqlplus recognizes it as the end of the SQL?statement. While for PL/SQL?it is part of the grammar and must must explicitly tell sqlplus that the statement ends here and should be executed by using slash.
分号“;”? 不是 SQL? 语法的一部分,sqlplus 将其识别为 SQL? 语句的结尾。而对于 PL/SQL,它是语法的一部分,必须明确告诉 sqlplus 语句到这里结束,应该使用斜杠来执行。
The other sqlplus commands are "EXIT", "DEFINE" "VARIABLE"?"PRINT"?"SET <something>" (except SET ROLE).
其他 sqlplus 命令是 "EXIT", "DEFINE" "VARIABLE"?"PRINT"?"SET <something>"(SET ROLE 除外)。
On the other hand the Toad for example recognizes the end of the PL/SQL?block when it sees an empty line.
另一方面,例如,当 Toad 看到空行时,它会识别出 PL/SQL? 块的结尾。
回答by Eric
the / at the end is to tell the interpreter to execute the loaded script
最后的 / 是告诉解释器执行加载的脚本
basicaly you type stuff then type "/" and what you just typed will execute
基本上你输入东西然后输入“/”,你刚刚输入的将执行
回答by Nuno G
Both the slash and the "exit" make me suspect you are supposed to run this script from SQLPLUS. You may get an error if you try to submit it to Oracle in some other way. In that case, just get rid of both.
斜线和“退出”都让我怀疑你应该从 SQLPLUS 运行这个脚本。如果您尝试以其他方式将其提交给 Oracle,您可能会收到错误消息。在这种情况下,只需摆脱两者。
回答by Nuno G
It is not an error. It executes the script.
这不是错误。它执行脚本。
It is useful when you concatenate various scripts together in one file and want each separate task to execute before the next one.
当您将各种脚本连接到一个文件中并希望每个单独的任务在下一个任务之前执行时,这很有用。
ie Create function / Create stored procedure that uses the function
即创建函数/创建使用该函数的存储过程
Without the slash the stored procedure may get created with errors or may not get created.
如果没有斜线,存储过程可能会在创建时出错或无法创建。