为什么此过程不返回值?

时间:2019-01-05 23:37:28

标签: oracle plsql

这是我的代码:

$scope.roleIsSelected(role)

并且没有检测到错误。这是脚本输出:

ng-class="{'active':roleIsSelected(role)}"

唯一的问题是在dbms输出中我没有得到任何结果 并且新表仍然为空。

这是应该出现的内容:

SET SERVEROUTPUT ON;

CREATE OR REPLACE PROCEDURE fillHist_station
AS
    *--filling the cursor*
    CURSOR cur_newTab IS(
        SELECT s.NUM_STATION, extract (year from r.DATER), cl.NB_RESERV, SUM(p.MONTANT)
        FROM STATION s, HOTEL h, CHAMBRE c, RESERVATION r, CLIENTS cl, PAYEMENT p 
        WHERE s.NUM_STATION=h.NUM_STATION and h.NUM_HOTEL=c.NUM_HOTEL and c.IDCHAMBRE=r.IDCHAMBRE and r.NUMC=cl.NUMC and cl.NUMC=p.NUMC
        GROUP BY s.NUM_STATION, extract (year from r.DATER), cl.NB_RESERV);
                    V_numStation STATION.NUM_STATION%TYPE;
                    V_anne VARCHAR2(4);
                    V_nbreserve CLIENTS.NB_RESERV%TYPE;
                    V_revenu NUMBER(5);
                BEGIN
                    OPEN cur_newTab;
                    LOOP
*--fetching the values from the cursor in my variables*
                        FETCH cur_newTab INTO V_numStation, V_anne, V_nbreserve, V_revenu;
                                DBMS_OUTPUT.PUT_LINE(V_numStation||' '||V_anne||' '||V_nbreserve||' '||V_revenu);
                        EXIT WHEN cur_newTab%notfound;
*--inserting the values of the variables in a new table that i just created*
                        INSERT INTO HIST_STATION ("NUM_STATION","ANNEE","NB_RESERV","REVENU") VALUES(V_numStation,V_anne,V_nbreserve,V_revenu);
*--showing the values of the variables in the dbms output to see my results*
                        DBMS_OUTPUT.PUT_LINE(V_numStation||' '||V_anne||' '||V_nbreserve||' '||V_revenu);
                    END LOOP;
                    CLOSE cur_newTab;
                END fillHist_station;
                /
                SHOW ERRORS;

1 个答案:

答案 0 :(得分:1)

我希望您需要将变量(V_ *)移至“声明”部分。

尝试首先打印光标记录中的值,以确保光标正常工作。

SET SERVEROUTPUT ON;

CREATE OR REPLACE PROCEDURE fillHist_station
AS
*--filling the cursor*
CURSOR cur_newTab IS(
    SELECT s.NUM_STATION,extract (year from r.DATER),cl.NB_RESERV,SUM(p.MONTANT)
       FROM STATION s, HOTEL h, CHAMBRE c, RESERVATION r, CLIENTS cl, PAYEMENT p 
       WHERE s.NUM_STATION=h.NUM_STATION and h.NUM_HOTEL=c.NUM_HOTEL and c.IDCHAMBRE=r.IDCHAMBRE and r.NUMC=cl.NUMC and cl.NUMC=p.NUMC
       GROUP BY s.NUM_STATION, extract (year from r.DATER), cl.NB_RESERV);
BEGIN
  FOR cur_newTab_rec  IN cur_newTab
  LOOP
    DBMS_OUTPUT.PUT_LINE(cur_newTab_rec.NUM_STATION);
  END LOOP;
CLOSE cur_newTab;
END fillHist_station;
/
SHOW ERRORS;