MySQL的確實有一個ISNULL ( )函式。然而,它的作品有點不同,微軟的ISNULL ( )函式。 MySQL中我們可以使用IFNULL ( )函式,就像這樣:
SELECT ProductName,UnitPrice*(UnitsInStock+IFNULL(UnitsOnOrder,0))
FROM Products
DECLARE
t_name VARCHAR2(10);
t_course1 NUMBER;
t_course2 NUMBER;
t_course3 NUMBER;
TYPE c_type IS REF CURSOR;
cur c_type;
BEGIN
OPEN cur FOR
"SELECT t_name,
SUM(CASE t_course WHEN """||"語文"||""" THEN t_score ELSE 0 END),
SUM(CASE t_course WHEN """||"數學"||""" THEN t_score ELSE 0 END),
SUM(CASE t_course WHEN """||"物理"||""" THEN t_score ELSE 0 END)
FROM tb GROUP BY t_name";
LOOP
FETCH cur INTO t_name,t_course1,t_course2,t_course3;
EXIT WHEN cur%NOTFOUND;
dbms_output.put_line(t_name||"語文"||t_course1||"數學"||t_course2||"物理"||t_course3);
END LOOP;
CLOSE cur;
MySQL的確實有一個ISNULL ( )函式。然而,它的作品有點不同,微軟的ISNULL ( )函式。 MySQL中我們可以使用IFNULL ( )函式,就像這樣:
SELECT ProductName,UnitPrice*(UnitsInStock+IFNULL(UnitsOnOrder,0))
FROM Products
DECLARE
t_name VARCHAR2(10);
t_course1 NUMBER;
t_course2 NUMBER;
t_course3 NUMBER;
TYPE c_type IS REF CURSOR;
cur c_type;
BEGIN
OPEN cur FOR
"SELECT t_name,
SUM(CASE t_course WHEN """||"語文"||""" THEN t_score ELSE 0 END),
SUM(CASE t_course WHEN """||"數學"||""" THEN t_score ELSE 0 END),
SUM(CASE t_course WHEN """||"物理"||""" THEN t_score ELSE 0 END)
FROM tb GROUP BY t_name";
LOOP
FETCH cur INTO t_name,t_course1,t_course2,t_course3;
EXIT WHEN cur%NOTFOUND;
dbms_output.put_line(t_name||"語文"||t_course1||"數學"||t_course2||"物理"||t_course3);
END LOOP;
CLOSE cur;