开发者

How can I get first column in oracle table?

I n开发者_运维百科eed to get first column in a oracle table for my select query i.e. SELECT FIRST_COLUMN from TABLE. How can I do this? I do not have access to SYS tables i.e no access to tables like user_tab_columns. Is it possible to do so?


You ALWAYS have access to USER_TAB_COLUMNS.

Too much stuff breaks if the DBA tries to revoke it.


Sounds like you have very limited access. If your accounts has access to DBMS_SQL you could try the following:

declare
lv_stat VARCHAR2(300) := 'SELECT * FROM tablename';
lv_cid integer;
lv_tab DBMS_SQL.DESC_TAB;
lv_cnt int;
begin
  lv_cid := DBMS_SQL.OPEN_CURSOR;
  DBMS_SQL.PARSE(lv_cid,lv_stat,DBMS_SQL.NATIVE);
  DBMS_SQL.DESCRIBE_COLUMNS(lv_cid,lv_cnt,lv_tab);
  DBMS_OUTPUT.PUT_LINE('First Column is '||lv_tab(1).col_name);
  DBMS_SQL.CLOSE_CURSOR(lv_cid);
  EXCEPTION
  when others then
  DBMS_SQL.CLOSE_CURSOR(lv_cid);
end;

This could be wrapped into a PL/SQL function. Probably simpler to talk to your DBAs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜