Académique Documents
Professionnel Documents
Culture Documents
Formatting Columns
Through the SQL*Plus COLUMN command, you can change the column headings and reformat the column data in your query results.
FROM EMP;
300
11 rows selected.
MONTHLI NAME SALARY ==================== ========== clark 2450 king 5000 smith 2500 adams 2500 ford 2500 scott 2500 johns 2500 allen 1600 blake 2850 james 950 turner 1500 11 Rows selected.
Output: MONTHLY NAME SALARY ==================== ======== clark $2,450 king $5,000 smith $2,500 adams $2,500 ford $2,500 scott $2,500 johns $2,500 allen $1,600 blake $2,850 james $950 turner $1,500 11 rows selected.
If the WRAP variable of the SET command is set to ON (its default value), the employee names wrap to the next line after the fourth character. If WRAP is set to OFF, the names are truncated (cut off) after the fourth character.
Syntax: COLUMN COL_NAME LIKE DISPLAY_COL_NAME HEADING DISPLAY_TEXT Ex: COLUMN COMM LIKE SAL HEADING BONUS; SELECT ENAME,SAL,COMM FROM EMP; Output: MONTHLI NAME SALARY BONUS
===== ======== ======== clark king smith adams ford scott johns allen blake james turner $2,450 $5,000 $2,500 $2,500 $2,500 $2,500 $2,500 $1,600 $2,850 $950 $1,500 $0 $300 $0 $0
11 rows selected.
To list the current display attributes for all columns, enter the COLUMN command with no column names or clauses after it: Syntax: COLUMN To reset the display attributes for a column to their default values, use the CLEAR clause of the COLUMN command as shown: Syntax: COLUMN [column_name] CLEAR Ex: CLEAR COLUMNS; Output: Columns cleared
Output: ENAME ==================== king smith adams ford scott allen james turner
8 rows selected.
OFF tells SQL*Plus to use the default display attributes for the column, but does not remove the attributes you have defined through the COLUMN command. To restore the attributes you defined through COLUMN, use the ON clause:
EMP MONTHLY NAME SALARY ====== ========== king smith $5000.00 $2500.00
DEPTNO ========== 10 20
adams $2500.00 ford scott allen james $2500.00 $2500.00 $1600.00 $950.00 30
turner $1500.00
8 rows selected.
10
----------------- ------------king 10
20
30
8 rows selected.
11
Output:
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM ----------
DEPTNO -----------20
--------- -------------------- ---------- ---------- --------- ---------- ---------7369 smith clerk 7902 17-DEC-80 2500
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO ------------30
--------- ---------------- ---------- ---------- ------------------ ---------- ---------7499 allen sales man 7698 20-FEB-81 1600 300
12
---------- -------------------- ---------- ---------- --------- ---------- ---------- ---------7369 smith clerk 7902 17-DEC-80 2500
7499
allen
1600
300
30
13
Output:
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ----------20
---------- -------------------- ---------- ---------- --------- ---------- ---------- ---------7369 smith clerk 7902 17-DEC-80 2500
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO ----------30
---------- -------------------- ---------- ---------- ----------------7499 allen sales man 7698 20-FEB-81
14
---------- -------------------- ---------- ---------- ---------------7782 7839 clark king manager 7839 09-JUN-81 president 17-NOV-81
---------- ---------0 0 10
MGR
HIREDATE
SAL
COMM
DEPTNO ---------20
---------- --------------7902 17-DEC-80 7788 23-MAY-87 7566 03-DEC-81 7566 19-APR-87 7839 02-APR-81
EMPNO ----------
ENAME ----------
MGR
HIREDATE
SAL
COMM
DEPTNO ---------30
15
Syntax: TTITLE FORMAT NO DISPLAY_STRING Ex: SQL> TTITLE FORMAT 9 'WELCOME' SQL> SELECT * FROM EMP WHERE EMPNO<=7500;
Output: WELCOME EMPNO ENAME ---------- -----------7369 smith JOB MGR HIREDATE SAL COMM DEPTNO
WELCOME EMPNO ENAME ---------- -----------7499 allen JOB MGR HIREDATE SAL COMM DEPTNO
16
Ex: SQL> TTITLE FORMAT 9 'PAGE:'SQL.PNO SQL> SELECT * FROM EMP WHERE EMPNO<=7500; PAGE: 1 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO -----------------20
---------2500
---------- -------------------- ---------- ---------- ---------------- ---------- ---------- -------------7499 allen sales man 7698 20-FEB-81 1600 300 30
17
---------- ------------ ------- ---------- -------------------- ---------- ---------7839 king president 17-NOV-81 5000 ---------5000 7369 smith clerk 7902 17-DEC-80 2500 2500 2500 2500 ---------10000 7499 allen 7900 james 7844 turner sales man 7698 20-FEB-81 clerk salesman 7698 03-DEC-81 7698 08-SEP-81 1600 950 1500 ---------4050 8 rows selected. sum sum 300 0
********** sum 20
**********
30
0 **********
18
MGR
HIREDATE
SAL
COMM
DEPTNO ---------10 20
---------- ------------ ------- ---------- -------------------- ---------- ---------7839 king president 7902 17-NOV-81 17-DEC-80 5000 2500 2500 2500 2500 1600 950 1500 ------------19000 0 300 0
7369 smith clerk 7876 Adams clerk 7902 ford 7788 Scott 7499 Allen 7900 James 7844 turner TOTAL
7788 23-MAY-87
30
19
OF col_name
EMP MONTHLY NAME SALARY ====== ========== king smith adams ford scott allen james turner $5000.00 $2500.00 $2500.00 $2500.00 $2500.00 $1600.00 $950.00 $1500.00 ---------------SUM AVG $19050.00 2381.25
20
Output:
To remove all COMPUTE definitions and the accompanying BREAK definition, enter the following commands: Syntax: CLEAR COMPUTES Ex: SQL> CLEAR COMPUTES Output: COMPUTES CLEARED
21
22
Setting the Top and Bottom Titles and Headers and Footers
As you have already seen, you can set a title to display at the top of each page of a report. You can also set a title to display at the bottom of each page. The TTITLE command defines the top title; the BTITLE command defines the bottom title. You can also set a header and footer for each report. The REPHEADER command defines the report header; the REPFOOTER command defines the report footer. A TTITLE, BTITLE, REPHEADER or REPFOOTER command consists of the command name followed by one or more clauses specifying a position or format and a CHAR value you wish to place in that position or give that format. You can include multiple sets of clauses and CHAR values: TTITLE position_clause(s) char_value position_clause(s) char_value ... BTITLE position_clause(s) char_value position_clause(s) char_value ... REPHEADER position_clause(s) char_value position_clause(s) char_value ... REPFOOTER position_clause(s) char_value position_clause(s) char_value ...
Syntax:
TTITLE ALINMENT STRING TO BE DISPLAY ON THE TOP BTITLE ALINMENT STRING TO BE DISPLAY ON THE BOTTOM Ex: SQL> TTITLE CENTER WELCOME SQL> BTITLE CENTER THANK YOU SQL> SELECT * FROM EMP WHERE EMPNO<=7500; Output: WELCOME
SAL
COMM
DEPTNO
---------- ------------ ------- ---------- -------------------- ---------- ---------- -----------7369 smith 7499 allen clerk sman 7902 17-DEC-80 7698 20-FEB-81
THANK YOU
20 30
23
24