2008-10-10 213 views
7

我正在爲用Oracle PL/SQL編寫的公司編寫一系列SQL腳本。我遇到了一個基本腳本,在底部附近有一個奇怪的斜線。它以這種方式檢入CVS。這是純粹的語法錯誤還是它有一些我不知道的功能。略微模糊的腳本:Oracle PL/SQL腳本中的斜線字符是否出錯?

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; 

回答

21

斜線具有a meaning

執行了最近執行的 SQL命令或PL/SQL塊其是存儲 在SQL緩衝區中。您可以在命令 提示或 多行命令的行號提示符處輸入斜槓(/) 。斜槓命令 的功能與RUN類似,但 不會列出該命令。

5

的/結尾是告訴譯員

basicaly執行加載腳本,你鍵入的東西,然後輸入「/」和你剛纔輸入的字符將執行

1

這不是錯誤。它執行腳本。

將各種腳本連接在一個文件中並希望每個單獨的任務在下一個文件之前執行時非常有用。

即創建功能 / 創建使用功能

沒有存儲的過程可能會與錯誤產生的斜線或可能不會創建存儲過程。

3

斜槓和「退出」讓我懷疑你應該從SQLPLUS運行這個腳本。如果您嘗試以其他方式將其提交給Oracle,您可能會遇到錯誤。在這種情況下,只需擺脫兩者。

6

使用Oracle時,您可以「混合」三種不同的語法。

  • SQL
  • PL/SQL
  • SQLPLUS(命令行客戶機)

SQLPLUS可以執行/處理SQL並通過發送它們到DB服務器PL/SQL語句。而sqlplus命令由sqlplus本身解釋。

分號「;」不是SQL語法的一部分,sqlplus將其識別爲SQL語句的結尾。而對於PL/SQL,它是語法的一部分,必須明確告訴sqlplus該語句在這裏結束,並且應該使用斜槓執行。

其他sqlplus命令是「EXIT」,「DEFINE」「VARIABLE」「PRINT」「SET <東西>」(SET ROLE除外)。

另一方面,Toad例如在看到空行時識別PL/SQL塊的末尾。