我創建了一個功能:函數返回沒有在甲骨文
create or replace function get_columns
(v_table_name IN varchar2)
RETURN VARCHAR2
AS
v_columns_list VARCHAR2(2048);
BEGIN
SELECT listagg(column_name,',') WITHIN GROUP (ORDER BY column_name) AS t_list into v_columns_list
FROM ALL_TAB_COLUMNS WHERE owner='MyOwner' AND table_name=v_table_name;
RETURN v_columns_list;
END;
當我測試這個功能就沒什麼可輸出返回:
declare
v_columns_list varchar2(2048);
v_table_name varchar2(100) := 'MyTable';
begin
-- SELECT listagg(column_name,',') WITHIN GROUP (ORDER BY column_name) AS t_list INTO v_columns_list
-- FROM ALL_TAB_COLUMNS WHERE owner='MyOwner' AND table_name=v_table_name;
v_columns_list := get_columns(v_table_name);
dbms_output.put_line(v_columns_list);
end;
結果:
anonymous block completed
然而,當我測試相同的「SELECT INTO」語句,它工作正常,並返回串聯的字符串:
declare
v_columns_list varchar2(2048);
v_table_name varchar2(100) := 'MyTable';
begin
SELECT listagg(column_name,',') WITHIN GROUP (ORDER BY column_name) AS t_list INTO v_columns_list
FROM ALL_TAB_COLUMNS WHERE owner='MyOwner' AND table_name=v_table_name;
-- v_columns_list := get_columns(v_table_name);
dbms_output.put_line(v_columns_list);
end;
爲什麼會這樣呢?
爲什麼你一旦你有結果遞歸調用相同的函數? – kevinsky 2015-03-13 16:22:47
適合我。您確定dbms_output已啓用? – OldProgrammer 2015-03-13 17:11:49
你有'owner ='MyOwner''和'v_table_name varchar2(100):='MyTable';'。我認爲這些都是你給出的例子。在你的真實情況下,他們是大寫?如果不是,請嘗試使它們成爲大寫。 – Boneist 2015-03-13 17:19:16