我有一个如下所示的storerd程序,
CREATE FUNCTION select_transactions3(text, text, int)
RETURNS SETOF transactions AS
$body$
DECLARE
rec transactions%ROWTYPE;
BEGIN
FOR rec IN (SELECT invoice_no, trans_date FROM transactions WHERE $1 = $2 limit $3 )
LOOP
RETURN NEXT rec;
END LOOP;
END;
$body$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
Run Code Online (Sandbox Code Playgroud)
当我执行这样的查询时:
select * from select_transactions3("invoice_no", '1103300105472',10);
Run Code Online (Sandbox Code Playgroud)
要么
select * from select_transactions3(invoice_no, '1103300105472',10);
Run Code Online (Sandbox Code Playgroud)
它得到这样的错误: 错误:列"invoice_no"不存在
但是当我尝试用这样的一个冒号执行时:
select * from select_transactions3('invoice_no', '1103300105472',10);
Run Code Online (Sandbox Code Playgroud)
结果是没有行.
我怎么能得到这样的数据:
invoice_no | trans_date
---------------+-------------------------
1103300105472 | 2011-03-30 12:25:35.694
Run Code Online (Sandbox Code Playgroud)
谢谢 .
更新:如果我们想要显示我们想要显示的某一列表
CREATE FUNCTION select_to_transactions14(_col character …
Run Code Online (Sandbox Code Playgroud)