问题描述
当我想在Oracle中看到一个包含其记录的表时,该表是杂乱无章的,我的意思是不像my-sql一样,在属性名下准确地看到每个属性值!我该如何解决呢?
when I want to see one table with its records in oracle, the table is disorganized,I mean is not like my-sql to see each value of attribute exactly under the name of attribute!how can I solve it?
推荐答案
您正在使用什么工具?
如果您使用的是命令行SQL * Plus,则可能需要使用格式命令来指定显示的宽度,即
If you are using the command-line SQL*Plus, you may need to use formatting commands to specify how wide the display should be, i.e.
丑陋的数据
SQL> select empno, ename, job, mgr, hiredate, sal, comm, deptno
2 from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM D
EPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- -----
-----
7369 smith CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1110
20
EMPNO ENAME JOB MGR HIREDATE SAL COMM D
EPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- -----
-----
7900 SM0 CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10
1234 FOO
15 rows selected.
但是如果我们指定EMPNO
和MGR
只能有5位数字的空间,并且ENAME
和JOB
应该以10个字符显示,那么一切都适合
But if we specify that EMPNO
and MGR
should only have room for 5 digits and ENAME
and JOB
should be displayed in 10 characters, everything fits
SQL> column empno format 99999;
SQL> column ename format a10;
SQL> column job format a10;
SQL> column mgr format 99999;
SQL> /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
------ ---------- ---------- ------ --------- ---------- ---------- ----------
7369 smith CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1110 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
------ ---------- ---------- ------ --------- ---------- ---------- ----------
7900 SM0 CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
1234 FOO
15 rows selected.
您也可以做类似的事情
SQL> set pagesize 100;
SQL> set linesize 120;
控制列标题的显示频率(默认每10行显示一次)以及每行应显示的宽度.
to control how frequently the column headers are displayed (the default is every 10 lines) and how wide each line should be.
当然,如果您只是编写临时查询的开发人员,则这种格式很麻烦.对于这种事情,使用Oracle的SQL Developer(Oracle免费提供的PL/SQL IDE)之类的东西要好得多. GUI会自动将结果显示在可以滚动浏览的表格中.
Of course, if you're just a developer writing ad-hoc queries, this sort of formatting is a pain. For that sort of thing, you're much better off using something like Oracle's SQL Developer, a free PL/SQL IDE Oracle provides. The GUI automatically displays your results in a table that you can scroll through.
这篇关于在SQL * Plus中格式化查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!