2014-01-26 40 views
0

當我在sql developer中運行下面的代碼時,出現以下錯誤。我找不到這個代碼有什麼問題。 概念:遊標Base1中的sql退居大約100行。我希望將這些行中的每一行用作目標cusor中的sql的輸入,這會進一步返回幾行。 我得到的錯誤是:PL/SQL中的參數化遊標

出現符號「(」期待之一時執行以下操作:成散

出現符號「;」期待以下操作之一時:從

(,%。

出現符號「CLOSE」在需要下列之一時:到底要不要編譯最終實例化爲了壓倒一切的靜態 成員構造圖

set serveroutput ON 

Declare 
    Type Beg_Ser_Tab1 Is Table Of DUMMY%Rowtype Index By Pls_Integer; 
    Type Beg_Ser_Tab2 Is Table Of DUMMY%Rowtype INDEX BY PLS_INTEGER; 
    L_Beg_Ser_Tab Beg_Ser_Tab1; 
    L_Beg_Ser_Tab_Fin Beg_Ser_Tab2; 

    result number; 

    CURSOR Base1 IS 

     select * from DUMMY c1 
     where status=976 and for_class_loc_project=1 
     and not exists 
      (select * from DUMMY c2 
      where c2.status=976 and c2.for_class_loc_project=1 
      and c2.end_series=c1.COLOUMN_X and c2.end_station=c1.beg_station) 
     and not exists 
      (select * from mv_station_Series t 
      where t.status in (SELECT ID FROM list_domain 
      WHERE LOWER (domainvalue) IN ('active', 'preliminary as-built', 'idle', 'construction')) 
      and c1.COLOUMN_X=t.id and c1.beg_station=t.beg_station 
      )  
     order by c1.id; 



    CURSOR target(v_id NUMBER) IS 

     Select * 
      From DUMMY Where COLOUMN_X in (
      Select ID From Station_Series Where 
      Status = 976 
      And Discharge_Subsys = (Select Discharge_Subsys From Station_Series Where Id = v_id) 
      And Line_Loop = (Select Line_Loop From Station_Series Where Id = v_id)) And Status In 
      (Select Id From List_Domain 
      Where Lower (Domainvalue) In ('active', 'preliminary as-built', 'idle', 'construction')) 
      Order By Beg_Station Asc; 

BEGIN 
    OPEN Base1; 
    FETCH Base1 BULK COLLECT INTO l_beg_ser_tab1; 
    EXIT WHEN l_beg_ser_tab1.count = 0; 
    FOR index1 IN 1..l_beg_ser_tab1.count 
     LOOP 
     Dbms_Output.Put_Line('For Beg Series '|| L_Beg_Ser_Tab1(Index1)); 
     Open Target(L_Beg_Ser_Tab1.COLOUMN_X); 
     FETCH target(l_beg_ser_tab1.COLOUMN_X) BULK COLLECT INTO l_beg_ser_tab_fin; 
     FOR index2 IN 1..l_beg_ser_tab_fin.count 
      LOOP 
      DBMS_OUTPUT.PUT_LINE('    '||l_beg_ser_tab_fin(index2)); 
      END LOOP; 
     CLOSE target; 

     DBMS_OUTPUT.PUT_LINE('---------------------------------------------------------'); 
     END LOOP; 
    CLOSE Base1; 
END 
+0

「COLOUMN」?此外,您正在使用大量不相關的子查詢而不是直接連接。有什麼理由呢? –

+0

我沒有使用聯接,因爲我只是想在當天獲得解決方案而不必擔心性能問題。是的,就像你說的那樣,加入會讓事情變得簡單,而且,我的代碼看起來很笨拙。我將練習連接並嘗試適應此代碼。 –

回答

2

我認爲一旦你有:

Open Target(L_Beg_Ser_Tab1.COLOUMN_X); 

你將不需要再次指定參數:

FETCH target(l_beg_ser_tab1.COLOUMN_X) B 

此外,隱式遊標通常要更快一些,也更容易代碼。爲什麼不使用它們?事實上,爲什麼不爲整個邏輯使用一個隱式遊標呢?