這開始讓我瘋狂,我無法找到爲什麼這不起作用的原因!Oracle函數返回Null?
表格上有觸發器,所以cityID和postcodeID會自動填充。此功能的目的是找到一個同名的城市並返回其ID,否則將其添加到表中並返回新的ID。
CREATE OR REPLACE FUNCTION resolveCity(cityNameIn IN VARCHAR2)
RETURN NUMBER AS
cityIDOut NUMBER;
BEGIN
SELECT cityID
INTO cityIDOut
FROM tblCities
WHERE cityName = cityNameIn;
IF cityIDOut IS NULL THEN
-- Add this city to the list
INSERT INTO tblCities (cityName)
VALUES (cityNameIn)
RETURNING cityID INTO cityIDOut;
END IF;
RETURN(cityIDOut);
END;
/
觸發器BEFORE插入或插入後? – Stilgar
之前,它從序列 – BartWD