你可以用DBMS_SQL处理,给你个例子:SET SERVEROUTPUT ON DECLARE c NUMBER; d NUMBER; col_cnt INTEGER; f BOOLEAN; rec_tab DBMS_SQL.DESC_TAB; col_num NUMBER; BEGIN c := DBMS_SQL.OPEN_CURSOR; DBMS_SQL.PARSE(c, 'SELECT * FROM DBA_USERS', DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);/* * Following loop could simply be for j in 1..col_cnt loop. * Here we are simply illustrating some of the PL/SQL table * features. */ col_num := rec_tab.first; IF (col_num IS NOT NULL) THEN LOOP DBMS_OUTPUT.PUT_LINE('col_name = ' || rec_tab(col_num).col_name); col_num := rec_tab.next(col_num); EXIT WHEN (col_num IS NULL); END LOOP; END IF;
DBMS_SQL.CLOSE_CURSOR(c); END; /
唉,管它多少列呢!所有的列都在一些系统的表中存着呢 查询表的所有列 select t.* from user_tab_columns t where t.table_name = 要查询的表名然后遍历这个结果集就可以了
DECLARE
c NUMBER;
d NUMBER;
col_cnt INTEGER;
f BOOLEAN;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
BEGIN
c := DBMS_SQL.OPEN_CURSOR; DBMS_SQL.PARSE(c, 'SELECT * FROM DBA_USERS', DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);/*
* Following loop could simply be for j in 1..col_cnt loop.
* Here we are simply illustrating some of the PL/SQL table
* features.
*/
col_num := rec_tab.first;
IF (col_num IS NOT NULL) THEN
LOOP
DBMS_OUTPUT.PUT_LINE('col_name = '
|| rec_tab(col_num).col_name);
col_num := rec_tab.next(col_num);
EXIT WHEN (col_num IS NULL);
END LOOP;
END IF;
DBMS_SQL.CLOSE_CURSOR(c);
END;
/
查询表的所有列
select t.* from user_tab_columns t where t.table_name = 要查询的表名然后遍历这个结果集就可以了