CREATE OR ALTER FUNCTION FN_CONTAR_ID (
    CAMPO_ID VARCHAR(20),
    TABELA VARCHAR(20))
RETURNS INTEGER
AS
declare variable sql varchar(100);
declare variable counter integer;
begin
    sql = 'SELECT COUNT('||:CAMPO_ID||') FROM '||:TABELA;
  execute statement sql into counter;
  return counter;
end