oracle 如何获得oracle表中的第一列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4460703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:12:54  来源:igfitidea点击:

How can I get first column in oracle table?

sqloracle

提问by Gaurav

I need 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?

我需要为我的选择查询获取 oracle 表中的第一列,即 SELECT FIRST_COLUMN from TABLE。我怎样才能做到这一点?我无权访问 SYS 表,即无法访问像 user_tab_columns 这样的表。有可能这样做吗?

回答by Gary Myers

You ALWAYS have access to USER_TAB_COLUMNS.

您始终有权访问 USER_TAB_COLUMNS。

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

如果 DBA 试图撤销它,太多的东西就会中断。

回答by stjohnroe

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

听起来您的访问权限非常有限。如果您的帐户可以访问 DBMS_SQL,您可以尝试以下操作:

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

这可以包装到一个 PL/SQL 函数中。与您的 DBA 交谈可能更简单