关于Oracle数据库格式列的一个简单问题
A simple question about Oracle database format column
在 Oracle 上,为了使用 sqlplus 将输出设置得更好,我们这样做了
column author format a15
column editor format a15
column title format a15...
问题很简单:设置 3 列的列大小很容易,但是如果我们有 7 列或更多列呢?是否可以为所有列设置默认列大小?
没有。默认情况下,字符串列的显示长度是数据库中该列的大小。因此,如果列定义为 varchar2(100)
,则 SQL*Plus 在结果集中保留 100 个字符。特定规则适用于日期、CLOB 或其他数据类型,但这可能不是您在这里要求的。
如果你想改变它,需要在 column-per-column 的基础上完成。
The default width of datatype columns is the width of the column in the database.
You can change the displayed width of a datatype or DATE, by using the COLUMN command with a format model consisting of the letter A
(for alphanumeric) followed by a number representing the width of the column in characters.
Within the COLUMN
command, identify the column you want to format and the model you want to use.
嗯,这是可能的 - 对于数字。您有 3 个选项可用:
COLUMN FORMAT
优先于
SET NUMFORMAT
优先于
SET NUMWIDTH
例如:
SQL> set numwidth 2
SQL> select sal from emp where rownum <= 2;
SAL
---
##
##
SQL> set numformat 90d0
SQL> select sal from emp where rownum <= 2;
SAL
--------
00,0
00,0
SQL> col sal format 9g990d00
SQL> select sal from emp where rownum <= 2;
SAL
------------
.000,00
.600,00
SQL>
不过,其他数据类型就没有这样的运气了。
在 Oracle 上,为了使用 sqlplus 将输出设置得更好,我们这样做了
column author format a15
column editor format a15
column title format a15...
问题很简单:设置 3 列的列大小很容易,但是如果我们有 7 列或更多列呢?是否可以为所有列设置默认列大小?
没有。默认情况下,字符串列的显示长度是数据库中该列的大小。因此,如果列定义为 varchar2(100)
,则 SQL*Plus 在结果集中保留 100 个字符。特定规则适用于日期、CLOB 或其他数据类型,但这可能不是您在这里要求的。
如果你想改变它,需要在 column-per-column 的基础上完成。
The default width of datatype columns is the width of the column in the database.
You can change the displayed width of a datatype or DATE, by using the COLUMN command with a format model consisting of the letter
A
(for alphanumeric) followed by a number representing the width of the column in characters.Within the
COLUMN
command, identify the column you want to format and the model you want to use.
嗯,这是可能的 - 对于数字。您有 3 个选项可用:
COLUMN FORMAT
优先于SET NUMFORMAT
优先于SET NUMWIDTH
例如:
SQL> set numwidth 2
SQL> select sal from emp where rownum <= 2;
SAL
---
##
##
SQL> set numformat 90d0
SQL> select sal from emp where rownum <= 2;
SAL
--------
00,0
00,0
SQL> col sal format 9g990d00
SQL> select sal from emp where rownum <= 2;
SAL
------------
.000,00
.600,00
SQL>
不过,其他数据类型就没有这样的运气了。