表格:
//team
name
--------
fly
box
fire
第二张表:
//player
name pname
--------------
fly abc
box gba
fly abcd
fly john
所以我尝试使用以下代码创建PL / SQL:
CREATE OR REPLACE FUNCTION test( tname in VARCHAR2 )
IS
total NUMBER := 0;
p_np player.pname%TYPE;
CURSOR c_player IS
SELECT LISTAGG(p.pname,',') within group(order by p.pname)
FROM player p where pname = tname;
BEGIN
SELECT count(*) into total from player where name =tname;
OPEN c_player;
FETCH c_player into p_no;
EXIT WHEN c_player%NOTFOUND;
DBMS_OUTPUT.PUT_LINE( total || ':' || p_np );
CLOSE c_player;
END test;
/
但是当我运行脚本时,我只想在我的sqlplus中输入一个输入:
EXECUTE test('fly');
但我的问题是使用SELECT语句来显示它。 我应该怎么做?
预期产出:
3 : abc , abcd , john
但我需要使用select语句
SELECT test('fly');