With Sql*plus we can build friendly outputs to meet the needs of diverse users.
In this example, a simple example is presented for the output of xls,html two format files via Sql*plus.
First create two scripts:
1.main.sql
To set the environment, invoke the specific function script
2. Function Script-get_tables.sql
Scripts to implement specific functions
With these two scripts, you can avoid redundant information in spool, as a reference to:
How to remove redundant information from spool in Sqlplus
Examples are as follows:
1.main.sql script:
[Email protected] utl_file]$ more Main.sqlset linesize, set term off verify off feedback off pagesize 999 Set markup h Tml on Entmap in spool on Preformat offspool Tables.xls@get_tables.sqlspool offexit
2.get_tables.sql script:
[Email protected] utl_file]$ more Get_tables.sql Select Owner,table_name,tablespace_name,blocks,last_analyzedfrom All_tables ORDER by 1, 2;
3. Execute and get output:
[[email protected] utl_file]$ sqlplus "/As SYSDBA" @mainSQL *plus:release 9.2.0.4.0-production on Mon Apr 25 10:30:11 2 005Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Connected to:oracle9i Enterprise Edition release 9.2.0.4.0-productionwith the partitioning optionjserver release 9.2.0.4 .0-productiondisconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0-productionwith the partitioning optionjse RVer Release 9.2.0.4.0-production[[email protected] utl_file]$ ls-l tables.xls-rw-r--r-- 1 Oracle DBA
Output as XLS file here, we can see the output effect:
To change the Main.sql script, spool Tables.xls to spool tables.htm, we can get the output of the HTM format, such as:
Use Sql*plus to build perfect Excel or HTML output