问题遇到的现象和发生背景
Table:
Name Quantity
Aau 9
Bik 10
aAC 8
Ba 1
Cap 12
Ddaa 2
模糊查询含有‘AA’ 的name 以及 quantity, 输入“AA”后, 输出:
Aau 9 boxes
aAC 8 boxes
Ddaa 2 boxes
使用 Function, iLike, postgresql
问题相关代码,请勿粘贴截图
CREATE or REPLACE FUNCTION Inventory (partial_title text)
RETURNS setof text
AS $$
DECLARE
_result record;
BEGIN
for _result in
SELECT title, quantity
FROM Table
WHERE name ilike '%text%'
ORDER by name ASC
loop
return next 'name: '||_result.name || '; quantity: '||_result.quantity::text; 'boxes'
end loop;
if(not found) then
return next 'Ooops, no matching name !!';
end if;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM Table ( '%AA%')
运行结果及报错内容
Ooops, no matching titles !!
我想要达到的结果
Aau 9 boxes
aAC 8 boxes
Ddaa 2 boxes