CREATE OR REPLACE FUNCTION GET_SBG_HEIGHT_DIFF(
  P_CDFILIAL IN VARCHAR2,
  P_CDCIA IN VARCHAR2,
  P_CDMANCIA IN VARCHAR2,
  P_NRSERVICOCIAFILI IN NUMBER,
  P_CDCLASSE IN VARCHAR2,
  P_CDSUBGRU IN VARCHAR2,
  P_NRSEQSUBGRUSEMAM IN NUMBER,
  P_CDCICLO IN VARCHAR2
) RETURN NUMBER IS
  SBGH INT;
  MAX_SBGH INT;
  DIFF INT;
BEGIN
  SBGH := GET_SBG_HEIGHT(P_CDFILIAL, P_CDCIA, P_CDMANCIA, P_NRSERVICOCIAFILI, P_CDCLASSE, P_CDSUBGRU, P_NRSEQSUBGRUSEMAM, P_CDCICLO);
  MAX_SBGH := GET_SBG_MAX_HEIGHT(P_CDFILIAL, P_CDCIA, P_CDMANCIA, P_NRSERVICOCIAFILI, P_CDCLASSE, P_CDSUBGRU, P_NRSEQSUBGRUSEMAM);
  RETURN MAX_SBGH - SBGH;
END;
/