2016-06-17 57 views
3

我必須做學校的作業,但我得到兩個錯誤:數據庫PL/SQL

出現符號「Fetch」以下的預期時: 恆異常<an identifier><a double-quoted delimited-identifier>表LONG_雙裁判焦時間時間戳 間隔日期二進制民族性格的nchar

遇到個Ë符號「檔案結尾」期待 之一以下時:到底要不要編譯最終實例化爲了重寫靜態 成員構造圖

這裏是鏈接到我的代碼:http://pastebin.com/h4JN9YQY

CREATE OR REPLACE PROCEDURE generate_bonus 
AS 

cursor student_info is 
    select distinct students.id, 
    events.begindatetime, 
    events.enddatetime, 
    count(items.number_of_coupons) as coupons_collected, 
    events.type from students 
    join applies on applies.students_id = students.id 
    join schedules on schedules.id = applies.schedules_id 
    join events on events.id = schedules.events_id 
    join orders on orders.students_id = students.id 
    join orderitems on orderitems.orders_id = orders.id 
    join items on items.id = orderitems.items_id 
    join bars on bars.id = orders.bars_id 
    where applies.status = 'PLANNED' 
    and orderitems."NUMBER" is not null 
    and bars.name is not null 
    group by students.id, events.begindatetime, events.enddatetime, events.type 
    order by students.id; 

BEGIN 

    DECLARE 
    s_id integer(256); 
    s_beginDate date; 
    s_endDate date; 
    s_noCoupons number(256); 
    s_eventType varchar2(256); 
    s_workedHours number(24) := 8; 
    calculated_bonus number(256); 
    count_rows integer(256); 

    OPEN student_info; 

     LOOP 

     FETCH student_info into s_id, s_beginDate, s_endDate, s_noCoupons, s_eventType; 

      Select count(*) into count_rows from student_bonus where students_id = s_id and rownum <= 1; 

     EXIT WHEN count_rows = 1; 

      IF (s_eventType = 'ROUGH') THEN 
       calculated_bonus := s_workedHours * (s_workedHours/100 * 7) * s_noCoupons; 

       INSERT INTO student_bonus(students_id, bonus, events_id) VALUES (s_id, calculated_bonus, s_eventType); 

       calculated_bonus := 0; 

      ELSIF (s_eventType = 'NORMAL') THEN 
       calculated_bonus := s_workedHours * (s_workedHours/100 * 4) * s_noCoupons; 

       INSERT INTO student_bonus(students_id, bonus, events_id) VALUES (s_id, calculated_bonus, s_eventType); 

       calculated_bonus := 0; 

      ELSE 
       calculated_bonus := s_workedHours * (s_workedHours/100 * 2) * s_noCoupons; 

       INSERT INTO student_bonus(students_id, bonus, events_id) VALUES (s_id, calculated_bonus, s_eventType); 

       calculated_bonus := 0; 
      END IF; 

     END LOOP; 

    CLOSE student_info; 

END generate_bonus; 
+0

直接在這裏粘貼你的代碼。 – CinCout

+0

請閱讀如何創建MCVE([MCVE])。您所展示的內容不太可能與MCVE接近。 –

+0

如果你的count_rows從0開始,你會永遠循環我猜,也許把它改爲「count_rows <= 1時退出」會有幫助 – Gar

回答

0

在我看來更容易爲晚輩用的是遊標循環,在這個項目中,您將避免這種錯誤。語法如:

FOR row_variable IN cursor LOOP 
dbms_output.put_line(row_variable.id); 
END LOOP; 

row_variable從每個遊標行中都保存了vale,並且您可以通過'。'輕鬆訪問它。 (點)運算符如row_variable.id 使用遊標循環可以避免提取數據時出現問題,注意打開/關閉遊標並擔心遊標空間外的輸出。 循環會準確循環多少個光標所指的項目,就像每個循環一樣。

0

把這條線:

EXIT WHEN student_info%NOTFOUND;

此行之後:

FETCH student_info into s_id, s_beginDate, s_endDate, s_noCoupons, s_eventType; 

你已經達到了你的光標結束,但沒有代碼,告訴它退出。

0

光標應該遵循步驟如下方式..

Open Cursor 
LOOP 
FETCH cursor 
EXIT Cursor condtion 

{-- 
Your rest of the code here 
--} 

end loop;