SQL*Plus is a not only the command-line interface to the database server, it is also a featured reporting tool with paging capabilities. The pagesize is the number of rows of one page. The default is 14 and the maximum is 50000. One of the common property of the page is the headers when selecting from a table.
SQL> sho pages
pagesize 14
SQL> select empno,ename from emp;
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
EMPNO ENAME
---------- ----------
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
This is rather an annoying effect of the default setting than a feature and there is no set pagesize unlimited. The only way to have the header only once, is to set the pagesize to the maximum or use this trick : set pages 0 emb on newp none. Unfortunately, the later does not work for HTML reporting.
One of the less known and advanced sql*plus capabilities is the title of the page.
Today on the developpez.net forums I had a question about generating a describe for each table in user_tables.
The short answer is select * from user_tab_columns
In my output, I want to have each table on a separate page, with the table_name in the title, and the column names, not null options and datatypes in the page.
First I want to have a page per table, this I can define with break
bre on table_name ski page
I want to have the table name in the title of the page, but not as a column. I add some blank lines in the top title and in the bottom title.
col table_name new_v table_name nopri
tti le table_name s 2
bti s 1
Finally I set the pagesize to something bigger than the maximum number of columns of tables plus 6 for header and title
set pages 0
col pages new_v pages nopri
select max(count(*))+6 pages
from user_tab_columns
where table_name in (‘EMP’,’DEPT’,’T’)
group by table_name;
set pages &pages
Now the select
select
table_name,
column_name “Name”,
decode(nullable,’N’,’NOT NULL’) “Null?”,
DATA_TYPE||
case when DATA_TYPE in (‘NUMBER’,’FLOAT’)
and (data_precision is not null
or data_scale is not null) then
‘(‘||nvl(DATA_precision,38)||
case when data_scale!=0 then
‘,’||DATA_SCALE
end
||’)’
when data_type like ‘%CHAR%’ then
‘(‘||DATA_LENGTH||’)’ end
“Type”
from user_tab_columns
where table_name in (‘EMP’,’DEPT’,’T’);
DEPT Name Null? Type ------------------------------ -------- -------------------- DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13) EMP Name Null? Type ------------------------------ -------- -------------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(7,2) DEPTNO NUMBER(2)
For a HTML report, set mark html on
set mark html on
/
DEPT |
Name | Null? | Type |
---|---|---|
DEPTNO | NOT NULL | NUMBER(2) |
DNAME | VARCHAR2(14) | |
LOC | VARCHAR2(13) |
EMP |
Name | Null? | Type |
---|---|---|
EMPNO | NOT NULL | NUMBER(4) |
ENAME | VARCHAR2(10) | |
JOB | VARCHAR2(9) | |
MGR | NUMBER(4) | |
HIREDATE | DATE | |
SAL | NUMBER(7,2) | |
COMM | NUMBER(7,2) | |
DEPTNO | NUMBER(2) |
This was very helpful to me! Thanks for writing about this topic.