ORACLE存储过程无法编译

时间:2015-01-22 17:19:33

标签: oracle stored-procedures

我正在努力解决这个问题,并且无法弄清楚为什么Oracle不编译以下存储过程, 错误是PL / SQL:ORA-00933:comando SQL terminato erroneamente,在包含`FROM storico_dipendente AS anag,

的行上

提前致谢

Paolo`

create or replace 
    PROCEDURE AVERAGE_VRE (
                p_refDate IN DATE ,
          p_level IN VARCHAR2 )
    /*
        Procedure Name: AVERAGE_VRE
        Author:         Paolo URSINI
        Date:           21 jan 2015
        Description:    this procedure compute the average amount from PAYROLL table
                        inserting into PAYROLL_CALCOLATO table.
                        The assumption is that every wage type is equally divided
                        by ALL THE ACTIVE EMPLOYEE
    */
    IS 
      FTE decimal(8,3) := 0;

    BEGIN    
      SELECT sum(percentuale_parttime) into FTE
        from storico_dipendente
        where TRUNC(data_inizio_variazione) <= p_refDate 
            and TRUNC(data_fine_variazione) >= p_refDate 
            and flag_status = 1;    

        INSERT INTO PAYROLL_CALCOLATO (
            MATRICOLA, 
            DATA_PY, 
            IMPORTO,
            ID_CODICE_VOCE,
            TM_INS,
            TM_UPD,
            ID_GRUPPO_DATI)
            SELECT 
                anag.MATRICOLA, voci.DATA_PY, (voci.sumImporto / FTE ), 
                voci.ID_CODICE_VOCE, 
                SYSDATE, 
                SYSDATE, 
                2           
            FROM storico_dipendente AS anag,
          (
            SELECT DATA_PY, ID_CODICE_VOCE, sum(IMPORTO_PY) sumImporto
              FROM PAYROLL 
              WHERE TRUNC(DATA_PY) = p_refDate
              GROUP BY DATA_PY, ID_CODICE_VOCE
          ) AS voci         
        where TRUNC(data_inizio_variazione) <= p_refDate 
            and TRUNC(data_fine_variazione) >= p_refDate 
            and flag_status = 1 and cod_livello = p_level;  

    END AVERAGE_VRE;

2 个答案:

答案 0 :(得分:3)

删除&#34; AS&#34;来自两个表/子查询别名。虽然Oracle允许您将AS与列别名一起使用,但它不是表别名的有效语法。

答案 1 :(得分:0)

已解决,问题出现在关键字AS的别名中。 以下代码正确编译

 CREATE OR REPLACE PROCEDURE AVERAGE_VRE (
            p_refDate IN DATE ,
      p_level IN VARCHAR2 )
/*
    Procedure Name: AVERAGE_VRE
    Author:         Paolo URSINI
    Date:           21 jan 2015
    Description:    this procedure compute the average amount from PAYROLL table
                    inserting into PAYROLL_CALCOLATO table.
                    The assumption is that every wage type is equally divided
                    by ALL THE ACTIVE EMPLOYEE
*/
IS 
  FTE decimal(8,3) := 0;

BEGIN    
  SELECT sum(percentuale_parttime) into FTE
    from storico_dipendente
    where TRUNC(data_inizio_variazione) <= p_refDate 
        and TRUNC(data_fine_variazione) >= p_refDate 
        and flag_status = 1 and cod_livello = p_level;    

    INSERT INTO PAYROLL_CALCOLATO (
        MATRICOLA , 
        DATA_PY, 
        IMPORTO,
        ID_CODICE_VOCE,
        TM_INS,
        TM_UPD,
        ID_GRUPPO_DATI)
        SELECT 
            anag.MATRICOLA ,voci.DATA_PY, (voci.sumImporto / FTE ), 
            voci.ID_CODICE_VOCE, 
            SYSDATE, 
            SYSDATE, 
            2         
        FROM storico_dipendente anag,
              (
                SELECT DATA_PY, ID_CODICE_VOCE, sum(IMPORTO_PY) sumImporto
                  FROM PAYROLL 
                  WHERE TRUNC(DATA_PY) = p_refDate
                  GROUP BY DATA_PY, ID_CODICE_VOCE
              ) voci            
    where TRUNC(data_inizio_variazione) <= p_refDate 
        and TRUNC(data_fine_variazione) >= p_refDate 
        and flag_status = 1 and cod_livello = p_level;  

END AVERAGE_VRE;