-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstoredfunctions
59 lines (37 loc) · 874 Bytes
/
storedfunctions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- Stored Functions
USE world_peace;
DROP FUNCTION IF EXISTS check_credit;
DELIMITER $$
CREATE FUNCTION check_credit (
requesting_customer_id CHAR(10),
request_amount INT
)
RETURNS BOOLEAN
DETERMINISTIC
BEGIN
RETURN
(
SELECT credit_limit FROM customer WHERE customer_id = requesting_get_qoh_ftncustomer_id
) >= request_amount;
END $$
DELIMITER ;
-- check to see if the function works
SET @approved = check_credit("C000000001", 9000000);
SELECT @approved;
-- -------------------------------------------------
DROP FUNCTION IF EXISTS get_qoh_ftn;
DELIMITER $$
CREATE FUNCTION get_qoh_ftn (
request_item_id CHAR(10)
)
RETURNS INT
DETERMINISTIC
BEGIN
RETURN
(
SELECT qoh FROM merchandise_item WHERE merchandise_item_id = request_item_id
);
END $$
DELIMITER ;
SET @qty = get_qoh_ftn("KYOTOCBOOK");
SELECT @qty;