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を使用する場合、3つの異なる文法を「混合」します。

  • 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

エラーではありません。スクリプトを実行します。

さまざまなスクリプトを 1 つのファイルに連結し、それぞれの個別のタスクを次のタスクの前に実行する場合に便利です。

ie 関数の作成 / 関数を使用するストアド プロシージャの作成

スラッシュがないと、ストアド プロシージャが作成されてエラーが発生したり、作成されなかったりする可能性があります。

于 2008-10-10T22:39:51.203 に答える