CREATE OR REPLACE FUNCTION RETORNA_COD_PARC(P_NRPARCELA IN VARCHAR2) RETURN VARCHAR2
AS
   V_RESULT    VARCHAR2(03);
   V_RESULTC   VARCHAR2(03);
   V_RESULTD   VARCHAR2(03);
   V_RESULTU   VARCHAR2(03);
   W_0         CHAR(1) := '0';
   W_1         CHAR(1) := '1';
   W_2         CHAR(1) := '2';
   W_3         CHAR(1) := '3';
   W_4         CHAR(1) := '4';
   W_5         CHAR(1) := '5';
   W_6         CHAR(1) := '6';
   W_7         CHAR(1) := '7';
   W_8         CHAR(1) := '8';
   W_9         CHAR(1) := '9';
   W_A         CHAR(1) := 'A';
   W_B         CHAR(1) := 'B';
   W_C         CHAR(1) := 'C';
   W_D         CHAR(1) := 'D';
   W_E         CHAR(1) := 'E';
   W_F         CHAR(1) := 'F';
   W_G         CHAR(1) := 'G';
   W_H         CHAR(1) := 'H';
   W_I         CHAR(1) := 'I';
   W_J         CHAR(1) := 'J';
   W_K         CHAR(1) := 'K';
   W_L         CHAR(1) := 'L';
   W_M         CHAR(1) := 'M';
   W_N         CHAR(1) := 'N';
   W_O         CHAR(1) := 'O';
   W_P         CHAR(1) := 'P';
   W_Q         CHAR(1) := 'Q';
   W_R         CHAR(1) := 'R';
   W_S         CHAR(1) := 'S';
   W_T         CHAR(1) := 'T';
   W_U         CHAR(1) := 'U';
   W_V         CHAR(1) := 'V';
   W_X         CHAR(1) := 'X';
   W_W         CHAR(1) := 'W';
   W_Y         CHAR(1) := 'Y';
   W_Z         CHAR(1) := 'Z';
BEGIN
   V_RESULTC := SUBSTR(P_NRPARCELA, 1, 1);
   V_RESULTD := SUBSTR(P_NRPARCELA, 2, 1);
   V_RESULTU := SUBSTR(P_NRPARCELA, 3, 1);

   V_RESULT  := CASE WHEN V_RESULTC = W_1 AND V_RESULTD = W_0 THEN V_RESULTU||W_A
                     WHEN V_RESULTC = W_1 AND V_RESULTD = W_1 THEN V_RESULTU||W_B
                     WHEN V_RESULTC = W_1 AND V_RESULTD = W_2 THEN V_RESULTU||W_C
                     WHEN V_RESULTC = W_1 AND V_RESULTD = W_3 THEN V_RESULTU||W_D
                     WHEN V_RESULTC = W_1 AND V_RESULTD = W_4 THEN V_RESULTU||W_E
                     WHEN V_RESULTC = W_1 AND V_RESULTD = W_5 THEN V_RESULTU||W_F
                     WHEN V_RESULTC = W_1 AND V_RESULTD = W_6 THEN V_RESULTU||W_G
                     WHEN V_RESULTC = W_1 AND V_RESULTD = W_7 THEN V_RESULTU||W_H
                     WHEN V_RESULTC = W_1 AND V_RESULTD = W_8 THEN V_RESULTU||W_I
                     WHEN V_RESULTC = W_1 AND V_RESULTD = W_9 THEN V_RESULTU||W_J
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_0 THEN V_RESULTU||W_K
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_1 THEN V_RESULTU||W_L
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_2 THEN V_RESULTU||W_M
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_3 THEN V_RESULTU||W_N
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_4 THEN V_RESULTU||W_O
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_5 THEN V_RESULTU||W_P
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_6 THEN V_RESULTU||W_Q
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_7 THEN V_RESULTU||W_R
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_8 THEN V_RESULTU||W_S
                     WHEN V_RESULTC = W_2 AND V_RESULTD = W_9 THEN V_RESULTU||W_T
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_0 THEN V_RESULTU||W_U
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_1 THEN V_RESULTU||W_V
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_2 THEN V_RESULTU||W_X
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_3 THEN V_RESULTU||W_W
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_4 THEN V_RESULTU||W_Y
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_5 THEN V_RESULTU||W_Z
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_6 THEN W_A||V_RESULTU
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_7 THEN W_B||V_RESULTU
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_8 THEN W_C||V_RESULTU
                     WHEN V_RESULTC = W_3 AND V_RESULTD = W_9 THEN W_D||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_0 THEN W_E||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_1 THEN W_F||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_2 THEN W_G||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_3 THEN W_H||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_4 THEN W_I||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_5 THEN W_J||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_6 THEN W_K||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_7 THEN W_L||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_8 THEN W_M||V_RESULTU
                     WHEN V_RESULTC = W_4 AND V_RESULTD = W_9 THEN W_N||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_0 THEN W_O||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_1 THEN W_P||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_2 THEN W_Q||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_3 THEN W_R||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_4 THEN W_S||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_5 THEN W_T||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_6 THEN W_U||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_7 THEN W_V||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_8 THEN W_X||V_RESULTU
                     WHEN V_RESULTC = W_5 AND V_RESULTD = W_9 THEN W_W||V_RESULTU
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_0 THEN W_Y||V_RESULTU
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_1 THEN W_Z||V_RESULTU
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_0 THEN W_A||W_A
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_1 THEN W_A||W_B
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_2 THEN W_A||W_C
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_3 THEN W_A||W_D
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_4 THEN W_A||W_E
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_5 THEN W_A||W_F
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_6 THEN W_A||W_G
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_7 THEN W_A||W_H
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_8 THEN W_A||W_I
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_2 AND V_RESULTU = W_9 THEN W_A||W_J
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_0 THEN W_A||W_K
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_1 THEN W_A||W_L
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_2 THEN W_A||W_M
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_3 THEN W_A||W_N
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_4 THEN W_A||W_O
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_5 THEN W_A||W_P
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_6 THEN W_A||W_Q
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_7 THEN W_A||W_R
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_8 THEN W_A||W_S
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_3 AND V_RESULTU = W_9 THEN W_A||W_T
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_0 THEN W_A||W_U
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_1 THEN W_A||W_V
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_2 THEN W_A||W_X
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_3 THEN W_A||W_W
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_4 THEN W_A||W_Y
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_5 THEN W_A||W_Z
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_6 THEN W_B||W_A
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_7 THEN W_B||W_B
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_8 THEN W_B||W_C
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_4 AND V_RESULTU = W_9 THEN W_B||W_D
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_0 THEN W_B||W_E
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_1 THEN W_B||W_F
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_2 THEN W_B||W_G
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_3 THEN W_B||W_H
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_4 THEN W_B||W_I
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_5 THEN W_B||W_J
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_6 THEN W_B||W_K
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_7 THEN W_B||W_L
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_8 THEN W_B||W_M
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_5 AND V_RESULTU = W_9 THEN W_B||W_N
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_0 THEN W_B||W_O
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_1 THEN W_B||W_P
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_2 THEN W_B||W_Q
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_3 THEN W_B||W_R
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_4 THEN W_B||W_S
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_5 THEN W_B||W_T
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_6 THEN W_B||W_U
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_7 THEN W_B||W_V
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_8 THEN W_B||W_X
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_6 AND V_RESULTU = W_9 THEN W_B||W_W
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_0 THEN W_B||W_Y
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_1 THEN W_B||W_Z
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_2 THEN W_C||W_A
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_3 THEN W_C||W_B
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_4 THEN W_C||W_C
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_5 THEN W_C||W_D
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_6 THEN W_C||W_E
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_7 THEN W_C||W_F
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_8 THEN W_C||W_G
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_7 AND V_RESULTU = W_9 THEN W_C||W_H
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_0 THEN W_C||W_I
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_1 THEN W_C||W_J
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_2 THEN W_C||W_K
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_3 THEN W_C||W_L
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_4 THEN W_C||W_M
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_5 THEN W_C||W_N
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_6 THEN W_C||W_O
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_7 THEN W_C||W_P
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_8 THEN W_C||W_Q
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_8 AND V_RESULTU = W_9 THEN W_C||W_R
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_0 THEN W_C||W_S
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_1 THEN W_C||W_T
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_2 THEN W_C||W_U
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_3 THEN W_C||W_V
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_4 THEN W_C||W_X
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_5 THEN W_C||W_W
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_6 THEN W_C||W_Y
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_7 THEN W_C||W_Z
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_8 THEN W_D||W_A
                     WHEN V_RESULTC = W_6 AND V_RESULTD = W_9 AND V_RESULTU = W_9 THEN W_D||W_B
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_0 THEN W_D||W_C
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_1 THEN W_D||W_D
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_2 THEN W_D||W_E
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_3 THEN W_D||W_F
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_4 THEN W_D||W_G
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_5 THEN W_D||W_H
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_6 THEN W_D||W_I
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_7 THEN W_D||W_J
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_8 THEN W_D||W_K
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_0 AND V_RESULTU = W_9 THEN W_D||W_L
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_0 THEN W_D||W_M
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_1 THEN W_D||W_N
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_2 THEN W_D||W_O
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_3 THEN W_D||W_P
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_4 THEN W_D||W_Q
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_5 THEN W_D||W_R
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_6 THEN W_D||W_S
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_7 THEN W_D||W_T
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_8 THEN W_D||W_U
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_1 AND V_RESULTU = W_9 THEN W_D||W_V
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_2 AND V_RESULTU = W_0 THEN W_D||W_X
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_2 AND V_RESULTU = W_1 THEN W_D||W_W
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_2 AND V_RESULTU = W_2 THEN W_D||W_Y
                     WHEN V_RESULTC = W_7 AND V_RESULTD = W_2 AND V_RESULTU = W_3 THEN W_D||W_Z
				ELSE
                     W_A||W_A
				END;
   RETURN V_RESULT;
END;
/

