根据dseibert的回答,我创建了使用函数:
create type cols_name
as table of varchar2(32767)
/
CREATE OR REPLACE FUNCTION GET_COLUMNS_NAME(p_selectQuery IN VARCHAR2) RETURN cols_name PIPELINED IS
v_cursor_id integer;
v_col_cnt integer;
v_columns dbms_sql.desc_tab;
begin
v_cursor_id := dbms_sql.open_cursor;
dbms_sql.parse(v_cursor_id, p_selectQuery, dbms_sql.native);
dbms_sql.describe_columns(v_cursor_id, v_col_cnt, v_columns);
for i in 1 .. v_columns.count loop
pipe row(v_columns(i).col_name);
end loop;
dbms_sql.close_cursor(v_cursor_id);
return;
exception when others then
dbms_sql.close_cursor(v_cursor_id);
raise;
end;
/
使用它:
select * from TABLE(get_columns_name('select 1 column1, 2 column2 from dual'));
结果:
**COLUMN_VALUE**
COLUMN1
COLUMN2