I want to Write a function that returns the Products brought in a given month.
I tried this
create or replace
function myfun(mymonth date)
return date
is
cursor cur
is
select *
from products
where purchase_date=mymonth;
begin
for i in cur
loop
dbms_output.put_line(i.product_id || ', ' ||
i.description || ', ' ||
i.product_name || ', ' ||
i.quantity || ', ' ||
i.price || ', ' ||
i.purchase_date);
end loop;
return 1;
end;
this giving me error.
how can i pass month to pl/sql function and retrieve the data.
Pass in a date (’01-MAY-2003′) and use date functions to make it work:
Using
TRUNC(x, 'MM')on the input month means you can pass in any date at teh query will run from the first day of the month.Alternatively, you could use the
LAST_DAY()function which returns the start of the last day of the input month. You’d have to watch out for time values, since the Oracle DATE datatype can include both date and time.