The document contains examples of MySQL functions and procedures. It defines functions that return values based on calculations or conditions from tables. It also defines procedures that select and return values without parameters or insert/update data. The procedures and functions are called to demonstrate their use.
The document contains examples of MySQL functions and procedures. It defines functions that return values based on calculations or conditions from tables. It also defines procedures that select and return values without parameters or insert/update data. The procedures and functions are called to demonstrate their use.
The document contains examples of MySQL functions and procedures. It defines functions that return values based on calculations or conditions from tables. It also defines procedures that select and return values without parameters or insert/update data. The procedures and functions are called to demonstrate their use.
RETURNS int BEGIN DECLARE total int; SELECT SUM(mark) INTO total FROM enrollment WHERE ID='95113000'; RETURN total; END CALL nama(‘9511300’)
2. CREATE PROCEDURE contoh(nilai int)
BEGIN SELECT IF(nilai%2= 0, 'genap', 'ganjil') AS hasil; END
CALL contoh(10);
3. CREATE FUNCTION contoh(nilai int)
RETURNS CHARACTER BEGIN DECLARE huruf char(10); SELECT IF(nilai%2= 0, 'genap', 'ganjil') INTO huruf; RETURN huruf; END
SELECT contoh(10);
4. CREATE PROCEDURE hasil(nilai int)
BEGIN SELECT IF(nilai<60,'C', IF(nilai<= 80,'B', 'A')) AS hasil; END CALL hasil(80);
5. CREATE FUNCTION contoh2(nilai int)
RETURNS CHAR(2) BEGIN DECLARE hasil CHAR(2); SELECT IF(nilai<60,'C', IF(nilai<= 80,'B', 'A')) INTO hasil; RETURN hasil; END
SELECT contoh2(80);
CREATE PROCEDURE tute(nilai Varchar(50))
BEGIN SELECT student.status, enrollment.tute_no FROM student, enrollment WHERE student.ID=enrollment.ID AND enrollment.tute_no='A'; END; CALL tute('A')
CREATE PROCEDURE tute_no(IN nilai Varchar(50))
BEGIN
SELECT COUNT(tute_no) FROM enrollment WHERE tute_no='A';