我已经查看过其他50条奇怪的类似错误消息,但我的问题似乎不符合任何其他类似的错误消息:
CREATE OR REPLACE FUNCTION P01
(
customer_name char
) RETURNS table(Vname char(50), T_Date date, Amount float(2))
AS $$
BEGIN
return query SELECT Vname, T_Date, Amount
FROM Vendor, Customer, Transctn
WHERE Transctn.Vno = Vendor.Vno AND Customer.Account = Transctn.Account AND Cname = customer_name;
END;
$$ LANGUAGE PLPGSQL;
EDIT ::
所以,现在我重做了代码,结果仍然是null。 Makes.No.Sense。
CREATE OR REPLACE FUNCTION P01(customer_name char(50)) RETURNS void AS
$BODY$
DECLARE
C1 CURSOR FOR SELECT Vname, T_Date, Amount
FROM Vendor, Customer, Transctn
WHERE Transctn.Vno = Vendor.Vno AND Customer.Account = Transctn.Account AND Cname = customer_name;
vname char(50);
t_date date;
amount float(2);
BEGIN
OPEN C1;
RAISE NOTICE 'here ';
LOOP
FETCH C1 INTO vname, t_date, amount;
EXIT WHEN NOT FOUND;
RAISE NOTICE 'Vendor Name: %', vname;
RAISE NOTICE 'Transaction date: %', t_date;
RAISE NOTICE 'Amount: %', amount;
RAISE NOTICE ' ';
END LOOP;
END;
$BODY$
LANGUAGE PLPGSQL;
该函数加载正常。但是,在尝试运行查询时:
SELECT * FROM Q01('Jones');
我现在得到所有的NULL。但是各种查询的行数正确。
有人可以帮我创建这个简单的函数,只是试图返回几条记录吗?
谢谢!