当前位置: 首页 > 知识库问答 >
问题:

ORA-01843:不是有效的月份报告

岳阳文
2023-03-14

我有一个在PL-SQL视图中使用的查询。该视图包含一个名为Jde_date的函数,该函数采用Julian格式的date参数并将其转换为Gregorian格式,它工作得很好。

查询如下:

select Cedula
              , Nombre
              , f_nacimiento              
              , fec_previa
              , round(dia) Dia_faltante
              , sexo
              , Edad
              , Fecha_Ingreso
              , Nombre_Empresa
              , NombreCargo
              , Nom_Oficio
              , UniddeNegocio
              , DesUniNeg
              , NombFte
              , TipoContrato
              , TipoSueldo
              , SalHora
              , Salario
              , cesantias
              , prima
              , vacaciones
              , Total_Prestaciones
              , estado
              , grupo_cotizante
              , tipo_cotizante
              , fondo_pensiones
             
from
(

SELECT distinct total.Cedula
              , total.NOMBRE
              , total.f_nacimiento              
              , total.fec_previa
              , to_date(total.fec_previa) - sysdate as dia
              , total.sexo
              , total.Edad
              , total.Fecha_Ingreso
              , total.Nombre_Empresa
              , total.NombreCargo
              , total.Nom_Oficio
              , total.UniddeNegocio
              , Total.DesUniNeg
              , total.NombFte
              , total.TipoContrato
              , total.TipoSueldo
              , total.SalHora
              , total.Salario
              , total.cesantias
              , total.prima
              , total.vacaciones
              , total.Total_Prestaciones
              , total.estado
              , total.grupo_cotizante
              , total.tipo_cotizante
              , total.fondo_pensiones
              
from
(
SELECT * FROM (
select  
   "F060116"."YAAN8" as AN8,
     TRIM("F060116"."YAALPH") as NOMBRE,
     TRIM("F060116"."YASSN") as Cedula,
   TIPODOC.NNQ70BRTXT as tipo_documento,
           "F0010"."CCNAME"  as Nombre_Empresa,
         "OFI"."DRDL01"  as Nom_Oficio,
         to_char(integral.JDE_DATE(YADSI), 'dd/mm/yyyy') as Fecha_Ingreso,
         "F0005"."DRDL01"  as estado,
          TRIM(tsal.drdl01) as TipoSueldo,
         "Tcon1".drdl01 as TipoContrato
        ,round(("F060116".yasal/100)/12) as Salario
         ,round(("F060116".yasal/100)/12/240) as SalHora
          ,round((("F060116".yasal/100)/12) * 0.0833) as CESANTIAS
         ,round((("F060116".yasal/100)/12) * 0.0833) as PRIMA
         ,round((("F060116".yasal/100)/12) * 0.0416) as VACACIONES
         ,round(((("F060116".yasal/100)/12) * 0.0833) + round((("F060116".yasal/100)/12) * 0.0833) + round((("F060116".yasal/100)/12) * 0.0416)) AS TOTAL_PRESTACIONES
         ,yasex as sexo         
         ,to_char(integral.JDE_DATE(yadob), 'dd/mm/yyyy') as f_nacimiento         
         
         ,case 
         when yasex = 'F' then to_char(add_months(add_months(to_char(integral.JDE_DATE(yadob), 'dd/mm/yyyy'),12*54),-4),'dd/mm/yyyy') 
         when yasex = 'M' THEN to_char(add_months(add_months(to_char(integral.JDE_DATE(yadob), 'dd/mm/yyyy'),12*59),-4),'dd/mm/yyyy') 
         END as fec_previa
                
         ,TRIM("Fpen"."DRDL01") as fondo_pensiones
         ,TRIM("gcoti"."DRDL01") as grupo_cotizante
         ,TRIM("tcoti"."DRDL01") as tipo_cotizante
         ,to_char(round((sysdate-integral.JDE_DATE(yadob))/365,2)) Edad
         ,"fte"."DRDL01" as NombFte
         ,to_char( integral.JDE_DATE(YADT) , 'dd/mm/yyyy') as FechaRetiro
            ,"F060116"."YAMCU" as UniddeNegocio
         ,"F0006"."MCDL01" as DesUniNeg
         ,"F5"."DRDL01"  as NombreCargo  
                                
 from   "PRODDTA"."F060116" "F060116"
 left join PRODCTL.F0005 TSAL on trim(TSAL.DRKY) = trim(YAP011) --tipo sueldo
             and TSAL.DRSY = '06'
             and TSAL.DRRT = '11'  
 left join  "PRODCTL"."F0005" "fte" on rtrim(ltrim("fte"."DRKY")) = rtrim("F060116"."YAP005")  --Frente trabajo
            and "fte"."DRSY" = '06'
            AND "fte"."DRRT" = '05'   
 left join "PRODDTA"."F0006" "F0006" on "F060116"."YAMCU"="F0006"."MCMCU"
 left join "PRODCTL"."F0005" "F0005" on rtrim("F060116"."YAPAST")= ltrim("F0005"."DRKY") --Estado Contrato
           and "F0005"."DRSY" = '06'
           AND "F0005"."DRRT" = 'PS'
 left join "PRODDTA"."F0010"  "F0010" on "F060116"."YAHMCO" = "F0010"."CCCO"
 left join  "PRODCTL"."F0005" "F5" on rtrim("F060116"."YAJBCD") = ltrim("F5"."DRKY") --cargo
            and "F5"."DRSY" = '06'
            AND "F5"."DRRT" = 'G'
 left join "PRODCTL"."F0005" "GPO" on rtrim(ltrim("GPO"."DRKY")) = rtrim("F060116"."YAP001") --Grupo de trabajo
            and "GPO"."DRSY" = '06'
            AND "GPO"."DRRT" = '01'
 left join "PRODCTL"."F0005" "OFI" on rtrim(ltrim("OFI"."DRKY")) = rtrim("F060116"."YAP002") --Oficio
            and "OFI"."DRSY" = '06'
            AND "OFI"."DRRT" = '02'
 left join  "PRODCTL"."F0005" "fte" on rtrim(ltrim("fte"."DRKY")) = rtrim("F060116"."YAP005") --Ubicacion
            and "fte"."DRSY" = '06'
            AND "fte"."DRRT" = '05'
left join  "PRODCTL"."F0005" "Tcon" on rtrim(ltrim("Tcon"."DRKY")) = rtrim("F060116"."YAP004") --Tipo jornada trabajo
            and "Tcon"."DRSY" = '06'
            AND "Tcon"."DRRT" = '04'   
left join  "PRODCTL"."F0005" "Tcon1" on rtrim(ltrim("Tcon1"."DRKY")) = rtrim("F060116"."YAP013") --Tipo de contrato
            and "Tcon1"."DRSY" = '06'
            AND "Tcon1"."DRRT" = '13'             
left join  "PRODCTL"."F0005" "Fpen" on rtrim(ltrim("Fpen"."DRKY")) = rtrim("F060116"."YAP017") --Fondo pensiones
            and "Fpen"."DRSY" = '06'
           AND "Fpen"."DRRT" = '17' 
left join  "PRODCTL"."F0005" "gcoti" on rtrim(ltrim("gcoti"."DRKY")) = rtrim("F060116"."YAP019") --Grupo cotizante
            and "gcoti"."DRSY" = '06'
            AND "gcoti"."DRRT" = '19' 
 left join  "PRODCTL"."F0005" "tcoti" on rtrim(ltrim("tcoti"."DRKY")) = rtrim("F060116"."YAP020") --Tipo cotizante
            and "tcoti"."DRSY" = '06'
            AND "tcoti"."DRRT" = '21'           

left join integral.REP_RENOVACION_CONTRATOS rct on trim(rct.CEDULA) = trim("F060116".YASSN)            
left join PRODDTA.f01151 correoe on trim(correoe.eaan8) = trim(F060116.yaan8)
and trim(EAIDLN) = '0'
LEFT JOIN proddta.FQ70C014 TIPODOC ON trim(TIPODOC.NNAN8) = trim(F060116.yaan8)
AND NNPN  = 0
    ) me 
left join (
select ALADD1 DIRECCION, alan8 from proddta.F0116
where (ALUPMJ,alan8) in
(select max(ALUPMJ),alan8
from proddta.F0116
group by alan8)
group by ALADD1 , alan8 ) direcci
on trim(ME.an8) = trim(direcci.alan8) 
left join (
select alan8,drdl01 departamento, ALCTY1 ciudad from proddta.F0116
LEFT JOIN  PRODCTL.F0005  
ON TRIM(DRKY) = trim(ALADDS)
and DRSY = '00'
AND DRRT = 'S'
where (ALEFTB,alan8) in
(select max(ALEFTB),alan8
from proddta.F0116
group by alan8)
group by alan8 , drdl01,ALCTY1
) ciu
on trim(ciu.alan8) = trim(ME.an8)
left join (
select tel.wpph1 telefono, tel.wpan8 
from proddta.F0115 tel 
where (tel.WPRCK7,tel.wpan8) in
(select max(tel.WPRCK7),tel.wpan8
from proddta.F0115 tel
where trim(tel.WPPHTP) = 'TEL'
group by tel.wpan8)
group by tel.wpph1 , tel.wpan8
)  telt 
on trim(ME.an8) = trim(telt.wpan8) 
left join (
select celu.wpph1 celular, celu.wpan8 
from proddta.F0115 celu 
where (celu.WPRCK7,celu.wpan8) in
(select max(celu.WPRCK7),celu.wpan8
from proddta.F0115 celu
where trim(celu.WPPHTP) = 'MOV'
group by celu.wpan8)
group by celu.wpph1 , celu.wpan8
) celut
on trim(ME.an8) = trim(celut.wpan8) ) total

 where  
     ((total.estado = 'Active' and total.grupo_cotizante = 'Dependiente' and total.tipo_cotizante ='N/A' and total.sexo ='M' 
   or (total.estado = 'Active' and total.grupo_cotizante = 'Dependiente' and total.tipo_cotizante ='Depend. pens por vejez activo' and total.sexo ='M') 
   or (total.estado = 'Active' and total.grupo_cotizante = 'Dependiente' and total.tipo_cotizante ='Cotizante con requisitos cumpl' and total.sexo ='M' ) 
   or (total.estado = 'Active' and total.grupo_cotizante = 'Dependiente' and total.tipo_cotizante ='Cotizante a quién reconoció In' and total.sexo ='M' )
  and  total.sexo = 'M') AND  total.sexo = 'M' and total.edad >=57 and total.edad <=59)
  
   OR 
    ((total.estado = 'Active' and total.grupo_cotizante = 'Dependiente' and total.tipo_cotizante ='N/A' and total.sexo ='F' 
   or (total.estado = 'Active' and total.grupo_cotizante = 'Dependiente' and total.tipo_cotizante ='Depend. pens por vejez activo' and total.sexo ='F') 
   or (total.estado = 'Active' and total.grupo_cotizante = 'Dependiente' and total.tipo_cotizante ='Cotizante con requisitos cumpl' and total.sexo ='F' ) 
   or (total.estado = 'Active' and total.grupo_cotizante = 'Dependiente' and total.tipo_cotizante ='Cotizante a quién reconoció In' and total.sexo ='F' ) 
  and  total.sexo = 'F') and total.sexo = 'F' and total.edad >=52 and total.edad <=54)
       
ORDER BY 7 desc)

但是当我发布报告时,我得到错误ORA-01843:不是一个有效的月份。

我该怎么解决?

共有1个答案

商泽宇
2023-03-14
to_date(total.fec_previa) - sysdate as dia

您没有指定转换中使用的格式模型,而是依赖NLS_date_format会话参数是否正确;相反,您应该明确使用的格式模型:

to_date(total.fec_previa, 'dd/mm/yyyy') - sysdate as dia
 类似资料: