1CREATE FUNCTION function_name … RETURN BOOLEAN IS
2 Definitions;
3BEGIN
4 Statement;
5 RETURN "Hello World!";
6END;
1 CREATE OR REPLACE FUNCTION get_total_sales(
2 in_year PLS_INTEGER
3)
4RETURN NUMBER
5IS
6 l_total_sales NUMBER := 0;
7BEGIN
8 -- get total sales
9 SELECT SUM(unit_price * quantity)
10 INTO l_total_sales
11 FROM order_items
12 INNER JOIN orders USING (order_id)
13 WHERE status = 'Shipped'
14 GROUP BY EXTRACT(YEAR FROM order_date)
15 HAVING EXTRACT(YEAR FROM order_date) = in_year;
16
17 -- return the total sales
18 RETURN l_total_sales;
19END;