Last active
January 8, 2016 15:38
-
-
Save hackvan/0e1b95d891bfff5169a3 to your computer and use it in GitHub Desktop.
PL/SQL Oracle: Utilizar arreglos del tipo clave -> valor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Declare | |
pevc_codlibori sfci001t.codlibro%Type := 'PUC001'; | |
pevc_codctaori sfci001t.codctaco%Type := '244001'; | |
pevc_nivan1ori sfci019t.nivanal1%Type := 'TNEG'; | |
pevc_codan1ori sfci019t.codniva1%Type := '1234'; | |
pevc_nivan2ori sfci019t.nivanal2%Type := 'NIT'; | |
pevc_codan2ori sfci019t.codniva2%Type := '5678'; | |
pevc_nivan3ori sfci019t.nivanal3%Type := 'VIGE'; | |
pevc_codan3ori sfci019t.codniva3%Type := '2016'; | |
pevc_nivan4ori sfci019t.nivanal4%Type; | |
pevc_codan4ori sfci019t.codniva4%Type; | |
pevc_nivan5ori sfci019t.nivanal5%Type; | |
pevc_codan5ori sfci019t.codniva5%Type; | |
pevc_codlibdes sfci001t.codlibro%Type := 'PUC002'; | |
pevc_codctades sfci001t.codctaco%Type := '244001'; | |
psvc_nivan1des sfci019t.nivanal1%Type := 'NIT'; | |
psvc_codan1des sfci019t.codniva1%Type := Null; | |
psvc_nivan2des sfci019t.nivanal2%Type := 'TNEG'; | |
psvc_codan2des sfci019t.codniva2%Type := Null; | |
psvc_nivan3des sfci019t.nivanal3%Type := Null; | |
psvc_codan3des sfci019t.codniva3%Type := Null; | |
psvc_nivan4des sfci019t.nivanal4%Type := Null; | |
psvc_codan4des sfci019t.codniva4%Type := Null; | |
psvc_nivan5des sfci019t.nivanal5%Type := Null; | |
psvc_codan5des sfci019t.codniva5%Type := Null; | |
Type nivhashtype Is Table Of sfci019t.codniva1%Type Index By sfci019t.nivanal1%Type; | |
vrNiveles nivhashtype; | |
psnu_coderror Integer; | |
psvc_menerror Varchar2(2000); | |
vgex_errorval Exception; | |
-- Función que permite buscar los niveles de analisis en el array y retornar el codigo a utilizar. | |
Function fvcObtenerCodNivel(pevc_nivanades In sfci019t.nivanal1%Type) Return sfci019t.codniva1%Type Is | |
vlvc_codanpro sfci019t.codniva1%Type; | |
Begin | |
vlvc_codanpro := Null; | |
If pevc_nivanades IS Not Null Then | |
Begin | |
vlvc_codanpro := vrNiveles(pevc_nivanades); | |
Exception | |
When Others Then | |
vlvc_codanpro := Null; | |
End; | |
End If; | |
Return vlvc_codanpro; | |
End fvcObtenerCodNivel; | |
Begin | |
psnu_coderror := 0; | |
psvc_menerror := Null; | |
-- Inicializar el array del tipo clave-valor. | |
If pevc_nivan1ori Is Not Null Then | |
vrNiveles(pevc_nivan1ori) := pevc_codan1ori; | |
End If; | |
If pevc_nivan2ori Is Not Null Then | |
vrNiveles(pevc_nivan2ori) := pevc_codan2ori; | |
End If; | |
If pevc_nivan3ori Is Not Null Then | |
vrNiveles(pevc_nivan3ori) := pevc_codan3ori; | |
End If; | |
If pevc_nivan4ori Is Not Null Then | |
vrNiveles(pevc_nivan4ori) := pevc_codan4ori; | |
End If; | |
If pevc_nivan5ori Is Not Null Then | |
vrNiveles(pevc_nivan5ori) := pevc_codan5ori; | |
End If; | |
dbms_output.put_line('#'||vrniveles.count); | |
If Nvl(vrniveles.count, 0) > 0 Then | |
-- Obtener el código del nivel de analisis a utilizar según el nivel de análisis configurado. | |
psvc_codan1des := fvcObtenerCodNivel(psvc_nivan1des); | |
psvc_codan2des := fvcObtenerCodNivel(psvc_nivan2des); | |
psvc_codan3des := fvcObtenerCodNivel(psvc_nivan3des); | |
psvc_codan4des := fvcObtenerCodNivel(psvc_nivan4des); | |
psvc_codan5des := fvcObtenerCodNivel(psvc_nivan5des); | |
End If; | |
dbms_output.put_line('Libro.: '||pevc_codlibdes||chr(10) | |
||'Cuenta: '||pevc_codctades||chr(10) | |
||'Niv1..: '||psvc_nivan1des||chr(10) | |
||'Cod1..: '||psvc_codan1des||chr(10) | |
||'Niv2..: '||psvc_nivan2des||chr(10) | |
||'Cod2..: '||psvc_codan2des||chr(10) | |
||'Niv3..: '||psvc_nivan3des||chr(10) | |
||'Cod3..: '||psvc_codan3des||chr(10) | |
||'Niv4..: '||psvc_nivan4des||chr(10) | |
||'Cod4..: '||psvc_codan4des||chr(10) | |
||'Niv5..: '||psvc_nivan5des||chr(10) | |
||'Cod5..: '||psvc_codan5des||chr(10) | |
); | |
Exception | |
When vgex_errorval Then | |
Null; | |
When others Then | |
dbms_output.put_line('Error técnico: '||sqlerrm); | |
End; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment