inventory_in_stock
Documentation | Sakila |
Name | inventory_in_stock |
Module | Functions |
The inventory_function function returns a boolean value indicating whether the inventory item specified is in stock.
Input/Output
Mode | Name | Data type | Description | |
---|---|---|---|---|
1 | OUT | Returns | tinyint(3, 0) | Returns TRUE or FALSE to indicate whether the item specified is in stock. |
Returns TRUE or FALSE to indicate whether the item specified is in stock. | ||||
2 | IN | p_inventory_id | int(10, 0) | The ID of the inventory item to be checked. |
The ID of the inventory item to be checked. |
Script
BEGIN DECLARE v_rentals INT; DECLARE v_out INT; #AN ITEM IS IN-STOCK IF THERE ARE EITHER NO ROWS IN THE rental TABLE #FOR THE ITEM OR ALL ROWS HAVE return_date POPULATED SELECT COUNT(*) INTO v_rentals FROM rental WHERE inventory_id = p_inventory_id; IF v_rentals = 0 THEN RETURN TRUE; END IF; SELECT COUNT(rental_id) INTO v_out FROM inventory LEFT JOIN rental USING(inventory_id) WHERE inventory.inventory_id = p_inventory_id AND rental.return_date IS NULL; IF v_out > 0 THEN RETURN FALSE; ELSE RETURN TRUE; END IF; END |
Exported: 2018-10-12 17:43, Last imported: 2018-08-06 10:44