代码之家  ›  专栏  ›  技术社区  ›  danieltalsky

Oracle PL/SQL脚本中的斜杠字符是错误的吗?

  •  7
  • danieltalsky  · 技术社区  · 16 年前

    我正在为我的公司整理一系列用OraclePL/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;
    
    5 回复  |  直到 11 年前
        1
  •  21
  •   Eddie Awad    16 年前

    斜杠有 a meaning :

    执行最近执行的 SQL命令或pl/sql块,即 存储在SQL缓冲区中。你可以 在命令处输入斜线(/) 提示或在行号处提示 多行命令。斜线命令 函数与run类似,但确实如此 不列出命令。

        2
  •  7
  •   ibre5041    11 年前

    当使用甲骨文时,你“混合”了三种不同的语法。

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

    sqlplus可以通过发送到db server来执行/处理sql_穖和pl/sql_穖。而sqlplus命令由sqlplus本身解释。

    分号“∧”不是sql∧语法的一部分,sqlplus将其识别为sql∧语句的结尾。而对于pl/sql_

    其他sqlplus命令为“exit”、“define”、“variable”___窆“set<something>”(set role除外)。

    另一方面,例如,当toad看到空行时,它会识别pl/sql_

        3
  •  5
  •   Eric    16 年前

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

    基本上你输入东西然后输入“/”,你刚输入的东西就会执行

        4
  •  3
  •   Nuno G    16 年前

    斜线和“出口”都让我怀疑您应该从sqlplus运行这个脚本。如果尝试以其他方式将其提交给Oracle,则可能会出现错误。那样的话,就把两者都去掉。

        5
  •  1
  •   user18443    16 年前

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

    当您将不同的脚本连接到一个文件中,并希望在下一个文件之前执行每个单独的任务时,这是非常有用的。

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

    如果不使用斜杠,存储过程可能会创建时出错,也可能不会创建。