7

我正在为我的公司整理一系列用 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;
4

5 回答 5

21

斜线有一个含义

执行存储在 SQL 缓冲区中的最近执行的 SQL 命令或 PL/SQL 块。您可以在命令提示符或多行命令的行号提示符处输入斜杠 (/)。斜杠命令的功能与 RUN 类似,但不列出该命令。

于 2008-10-10T22:20:43.287 回答
7

使用 Oracle 时,您“混合”了三种不同的语法。

  • SQL
  • PL/SQL
  • sqlplus(命令行客户端)

sqlplus 可以通过将 SQL 和 PL/SQL 语句发送到 DB 服务器来执行/处理它们。而 sqlplus 命令由 sqlplus 本身解释。

分号“;” 不是 SQL 语法的一部分,sqlplus 将其识别为 SQL 语句的结尾。而对于 PL/SQL,它是语法的一部分,必须明确告诉 sqlplus 语句到此结束,应该使用斜杠执行。

其他 sqlplus 命令是“EXIT”、“DEFINE”“VARIABLE”“PRINT”“SET <something>”(SET ROLE 除外)。

另一方面,当 Toad 看到空行时,它会识别 PL/SQL 块的结尾。

于 2013-02-27T09:20:53.460 回答
5

末尾的 / 是告诉解释器执行加载的脚本

基本上你输入东西然后输入“/”,你刚刚输入的内容将执行

于 2008-10-10T22:20:21.460 回答
3

斜杠和“退出”都让我怀疑您应该从 SQLPLUS 运行此脚本。如果您尝试以其他方式将其提交给 Oracle,您可能会收到错误消息。在这种情况下,只需摆脱两者。

于 2008-10-10T22:45:54.810 回答
1

这不是错误。它执行脚本。

当您将各种脚本连接到一个文件中并希望每个单独的任务在下一个任务之前执行时,它很有用。

即创建函数/创建使用该函数的存储过程

如果没有斜杠,存储过程可能会创建错误或可能无法创建。

于 2008-10-10T22:39:51.203 回答