SET TERM ^ ;
CREATE OR ALTER function FN_DIA_SEMANA (
    P_DATA date)
returns varchar(50)
AS
declare variable v_dia integer;
declare variable s_dia varchar(50);
begin

  V_DIA = EXTRACT(WEEKDAY FROM :P_DATA);
  S_DIA =
   CASE :V_DIA
     WHEN 0 THEN 'DOMINGO'
     WHEN 1 THEN 'SEGUNDA'
     WHEN 2 THEN 'TERCA'
     WHEN 3 THEN 'QUARTA'
     WHEN 4 THEN 'QUINTA'
     WHEN 5 THEN 'SEXTA'
     WHEN 6 THEN 'SABADO'
   END;

  return S_DIA;
end
^ SET TERM ; ^