CREATE OR REPLACE FUNCTION getExemplaryMaterialLocation(p_itemnumber varchar)
RETURNS TABLE (materiallocationid int) AS
/*************************************************************************************
  NAME: getExemplaryMaterialLocation
  DESCRIPTION: Obtém a localização de material do exemplar.
**************************************************************************************/
$BODY$ 
BEGIN
    RETURN QUERY SELECT getMaterialLocation(B.content, A.materialtypeid, A.materialphysicaltypeid, A.libraryunitid, A.exemplarystatusid, C.content)
                   FROM gtcexemplarycontrol A
             INNER JOIN gtcmaterial B ON (A.controlnumber = B.controlnumber AND B.fieldid = '090' AND B.subfieldid = 'a')
             INNER JOIN gtcmaterial C ON (A.controlnumber = C.controlnumber AND C.fieldid = '901' AND C.subfieldid = 'b')
                  WHERE A.itemnumber = p_itemnumber;    
          
END; 
$BODY$ 
language plpgsql;
