get_rental_duration() a
CREATE OR REPLACE FUNCTION get_rental_duration(p_customer_id INTEGER) RETURNS INTEGER AS $$ DECLARE rental_duration INTEGER; BEGIN -- get the rate based on film_id SELECT INTO rental_duration SUM( EXTRACT( DAY FROM return_date - rental_date)) FROM rental WHERE customer_id=p_customer_id; RETURN rental_duration; END; $$ LANGUAGE plpgsql;
get_rental_function p_customer_id 278 get_rental_duration
SELECT get_rental_duration(278);
Devuelve lo siguiente:
p_from_date get_rental_duration()
CREATE OR REPLACE FUNCTION get_rental_duration(p_customer_id INTEGER, p_from_date DATE) RETURNS INTEGER AS $$ DECLARE rental_duration integer; BEGIN -- get the rental duration based on customer_id and rental date SELECT INTO rental_duration SUM( EXTRACT( DAY FROM return_date + '12:00:00' - rental_date)) FROM rental WHERE customer_id= p_customer_id AND rental_date >= p_from_date; RETURN rental_duration; END; $$ LANGUAGE plpgsql;
get_rental_duration(entero, fecha) 2781 de julio de 2005
SELECT get_rental_duration(278, '2005-07-01');
Dará como resultado lo siguiente:
Publicación traducida automáticamente
Artículo escrito por RajuKumar19 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA