Documentos de Académico
Documentos de Profesional
Documentos de Cultura
FUNCIONES:
1-- SI ES LUNES
create FUNCTION Eslunes(fe date)
returns varchar (20)
begin
DECLARE x SMALLINT;
set x=(SELECT CASE EXTRACT(MONTH FROM(fe))
WHEN 0 THEN 'ENERO'
WHEN 1 THEN 'FEBRERO'
WHEN 2 THEN 'MARZO'
WHEN 3 THEN 'ABRIL'
WHEN 4 THEN 'MAYO'
WHEN 5 THEN 'JUNIO'
WHEN 6 THEN 'JULIO'
WHEN 7 THEN 'AGOSTO'
WHEN 8 THEN 'SEPTIEMBRE'
WHEN 9 THEN 'OCTUBRE'
WHEN 10 THEN 'NOVIEMBRE'
WHEN 11 THEN 'DICIEMBRE'
END );
return no ES UNA FECHA ;
end if
end;
2--- CALCULA FACTORIAL
create function factfind(@num integer)
returns Decimal(38,0)
as
begin
declare @Result Decimal(38,0)
set @Result = 1
if (@num>1)
set @Result = @num * dbo.factfind(@num-1);
return @Result
end
3---SI UN NUMERO ES PRIMO
FUNCTION is_prime (
number_in IN INTEGER)
RETURN BOOLEAN
IS
c_limit INTEGER := ABS ( number_in );
retval BOOLEAN DEFAULT TRUE;
divisor INTEGER := 2;
BEGIN
WHILE ( divisor < c_limit AND retval )
LOOP
retval := MOD ( number_in, divisor ) <> 0;
divisor := divisor + 1;
END LOOP;
RETURN retval;
END is_prime;