CREATE OR REPLACE FUNCTION CONSULTA_QUADRO_ALIQUOTAS(
  P_SGESTADOORIG IN VARCHAR2,
  P_SGESTADODEST IN VARCHAR2) RETURN VARCHAR2
IS
   V_VRALIQUOTA VARCHAR2(02);
BEGIN
   BEGIN
      SELECT CASE UPPER(P_SGESTADODEST) WHEN 'AC' THEN SGESTADODESTAC
                                        WHEN 'AL' THEN SGESTADODESTAL
                                        WHEN 'AM' THEN SGESTADODESTAM
                                        WHEN 'AP' THEN SGESTADODESTAP
                                        WHEN 'BA' THEN SGESTADODESTBA
                                        WHEN 'CE' THEN SGESTADODESTCE
                                        WHEN 'DF' THEN SGESTADODESTDF
                                        WHEN 'ES' THEN SGESTADODESTES
                                        WHEN 'GO' THEN SGESTADODESTGO
                                        WHEN 'MA' THEN SGESTADODESTMA
                                        WHEN 'MT' THEN SGESTADODESTMT
                                        WHEN 'MS' THEN SGESTADODESTMS
                                        WHEN 'MG' THEN SGESTADODESTMG
                                        WHEN 'PA' THEN SGESTADODESTPA
                                        WHEN 'PB' THEN SGESTADODESTPB
                                        WHEN 'PR' THEN SGESTADODESTPR
                                        WHEN 'PE' THEN SGESTADODESTPE
                                        WHEN 'PI' THEN SGESTADODESTPI
                                        WHEN 'RN' THEN SGESTADODESTRN
                                        WHEN 'RS' THEN SGESTADODESTRS
                                        WHEN 'RJ' THEN SGESTADODESTRJ
                                        WHEN 'RO' THEN SGESTADODESTRO
                                        WHEN 'RR' THEN SGESTADODESTRR
                                        WHEN 'SC' THEN SGESTADODESTSC
                                        WHEN 'SP' THEN SGESTADODESTSP
                                        WHEN 'SE' THEN SGESTADODESTSE
                                        WHEN 'TO' THEN SGESTADODESTTO END
        INTO V_VRALIQUOTA
        FROM QUADROALIQUOTA
       WHERE SGESTADOORIG = P_SGESTADOORIG;
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         V_VRALIQUOTA := 0;
   END;
   RETURN NVL(V_VRALIQUOTA, '0');
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('CONSULTA_QUADRO_ALIQUOTAS','6.05.xxx'); END;
/