-1
create or replace PROCEDURE ResumenActividadDiaria(Fecha DATE) AS
  CURSOR cur_trans IS
  SELECT t.idslot, t.tipotransaccion, t.transacciongeneral, t.valortransaccion,
         s.fila, s.columna
    FROM  transaccion t, slot s
    WHERE t.idslot = s.idslot AND
          t.transacciongeneral in (1,3) AND
          t.fechacreacion = Fecha
    ORDER BY s.fila, s.columna, t.tipotransaccion, t.transacciongeneral;            

  rs_trans cur_trans%ROWTYPE;       

  vlIdSlot NUMBER(10);
  vlTipoTransaccion NUMBER(1);
  vlTransaccionGeneral NUMBER(1);
  vlValorTransaccion NUMBER(10);
  vlFila NUMBER(2);
  vlColumna NUMBER(2);     
BEGIN
  dbms_output.put_line('Fecha ' );
  dbms_output.put_line('                          ------------------------------------------------------');
  OPEN cur_trans;

  FETCH cur_trans INTO rs_trans;
  WHILE cur_trans%found 
  LOOP
    FETCH cur_trans INTO rs_trans;
    dbms_output.put_line('Id         :' || rs_trans.vlIdSlot);
    dbms_output.put_line('Fila       :' || rs_trans.vlFila);
    dbms_output.put_line('Columna    :' || rs_trans.vlColumna);

    IF vlTransaccionGeneral = 1 THEN                
      IF vlTipoTransaccion = 1 THEN
        dbms_output.put_line('Billetes I :' || rs_trans.vlValorTransaccion);
      END IF;

      IF vlTipoTransaccion = 2 THEN
        dbms_output.put_line('Monedas  I :' || rs_trans.vlValorTransaccion);
      END IF;

      IF vlTipoTransaccion = 3 THEN
        dbms_output.put_line('Premios  I :' || rs_trans.vlValorTransaccion);
      END IF;

      IF vlTipoTransaccion = 4 THEN
        dbms_output.put_line('Creditos I :' || rs_trans.vlValorTransaccion);
      END IF;
    END IF;

    IF vlTransaccionGeneral = 3 THEN                
      IF vlTipoTransaccion = 1 THEN
        dbms_output.put_line('Billetes F :' || rs_trans.vlValorTransaccion);
      END IF;

      IF vlTipoTransaccion = 2 THEN
        dbms_output.put_line('Monedas  F :' || rs_trans.vlValorTransaccion);
      END IF;

      IF vlTipoTransaccion = 3 THEN
        dbms_output.put_line('Premios  F :' || rs_trans.vlValorTransaccion);
      END IF;

      IF vlTipoTransaccion = 4 THEN
        dbms_output.put_line('Creditos F :' || rs_trans.vlValorTransaccion);
      END IF;
    END IF; 
  END LOOP;

  CLOSE cur_trans;  
END;

在编译上述函数时,我收到以下错误:

Error(58,4): PLS-00103: Encountered the symbol ";" when expecting one of the following:     loop 

请帮我解决这个问题。

4

1 回答 1

1
LOOP
    FETCH cur_trans INTO rs_trans;
    dbms_output.put_line('Id         :' || rs_trans.vlIdSlot);
    dbms_output.put_line('Fila       :' || rs_trans.vlFila);
    dbms_output.put_line('Columna    :' || rs_trans.vlColumna);
    IF vlTransaccionGeneral = 1 THEN                
        IF vlTipoTransaccion = 1 THEN
            dbms_output.put_line('Billetes I :' || rs_trans.vlValorTransaccion);
        ELSIF vlTipoTransaccion = 2 THEN
            dbms_output.put_line('Monedas  I :' || rs_trans.vlValorTransaccion);
        ELSIF vlTipoTransaccion = 3 THEN
            dbms_output.put_line('Premios  I :' || rs_trans.vlValorTransaccion);
        ELSIF vlTipoTransaccion = 4 THEN
            dbms_output.put_line('Creditos I :' || rs_trans.vlValorTransaccion);
        END IF;
    ELSIF vlTransaccionGeneral = 3 THEN                
        IF vlTipoTransaccion = 1 THEN
            dbms_output.put_line('Billetes F :' || rs_trans.vlValorTransaccion);
        ELSIF vlTipoTransaccion = 2 THEN
            dbms_output.put_line('Monedas  F :' || rs_trans.vlValorTransaccion);
        ELSIF vlTipoTransaccion = 3 THEN
            dbms_output.put_line('Premios  F :' || rs_trans.vlValorTransaccion);
        ELSIF vlTipoTransaccion = 4 THEN
            dbms_output.put_line('Creditos F :' || rs_trans.vlValorTransaccion);
        END IF; 
    END IF;
END LOOP;

使用ELSIF而不是重复IF使用。它使代码可读并且生活更轻松。PS:未测试。

于 2012-06-26T00:31:41.233 回答