相当于 Oracle 的 SQL*Plus 中 MySQL 的 \G

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4193370/
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 21:58:13  来源:igfitidea点击:

Equivalent of MySQL's \G in Oracle's SQL*Plus

oraclesqlplus

提问by Adrian Smith

In Oracle's SQL*Plus, the results of a SELECT are displayed in a tabular manner. Is there a way to display a row in a key-value manner (like MySQL's \Goption)?

在 Oracle 的 SQL*Plus 中,SELECT 的结果以表格方式显示。有没有办法以键值方式显示一行(如 MySQL 的\G选项)?

The database I am working on (the schema is not defined by me) has a bunch of columns named e.g. YN_ENABLED(YN = yes no) which are CHAR(1). So when I do a query I get a result like

我正在处理的数据库(架构不是我定义的)有一堆名为例如YN_ENABLED(YN = yes no) 的列,它们是CHAR(1). 所以当我进行查询时,我得到的结果是

ID_MYTABLE   Y Y Y
------------ - - -
3445         Y N Y

So it's not really clear which columns have which values (without having the schema open in another window).

因此并不清楚哪些列具有哪些值(无需在另一个窗口中打开架构)。

回答by Tony Andrews

Not built in to SQL PLus, but Tom Kyte has provided a procedure called print_tablethat does this. You would run it like this:

不是内置于 SQL PLus,但 Tom Kyte 提供了一个名为print_table的过程来执行此操作。你会像这样运行它:

SQL> exec print_table ('select * from mytable where id_mytable=123');

And see results like:

ID_MYTABLE      : 123
YN_ENABLED      : Y
YN_SOMETHING    : N
...

回答by Leigh Riffel

I know your question is about SQL*PLus, but you might be interested to know that Oracle's SQL Developer can do this. The feature can be used by right clicking on the Query Results and selecting "Single Record View...".

我知道您的问题是关于 SQL*PLus,但您可能有兴趣知道 Oracle 的 SQL Developer 可以做到这一点。可以通过右键单击查询结果并选择“单记录视图...”来使用该功能。

回答by Peter Gluck

Here's a trick that may do in a pinch if you don't want to (or cannot) install a new procedure on your server:

如果您不想(或不能)在您的服务器上安装新程序,这里有一个技巧可能会在紧要关头做:

  1. Select the row (or rows) of interest in the Oracle SQL Developer query results window.
  2. Use shift-control-cin Oracle SQL Developer to copy the rows and headers to the clipboard.
  3. Paste into your favorite spreadsheet (e.g., MS Excel). Now you have records in rows.
  4. Copy the rows that you just pasted into the spreadsheet
  5. Use the "Paste Special - Transpose" feature of your spreadsheet program to paste the values into a new spreadsheet. Now your records should be in columns.
  1. 在 Oracle SQL Developer 查询结果窗口中选择感兴趣的一行(或多行)。
  2. 使用shift-control-cOracle SQL Developer中的行与头复制到剪贴板。
  3. 粘贴到您最喜欢的电子表格(例如 MS Excel)中。现在您在行中有记录。
  4. 复制刚刚粘贴到电子表格中的行
  5. 使用电子表格程序的“选择性粘贴 - 转置”功能将值粘贴到新电子表格中。现在您的记录应该在列中。

回答by sreimer

Coming in late, but I found this

来晚了,但我发现了这个

SQL> select * from xmltable('ROWSET/ROW/*' passing xmltype(cursor(select * from emp where rownum = 1
)) columns name varchar2(30) path 'node-name(.)', value varchar2(30) path '.');

Found here

这里找到