ttitle col 15 '我的报表' col 35 sql.pno
col deptno heading 部门号
col job heading 职位
col sum(sal) heading 工资总额
break on deptno skip 1
ttitle col 15 '我的报表' col 35 sql.pno
表示标题前空15列,后空35列
sql.pno 表示报表的第一页,第二页
break on deptno skip 1
get sql文件,读取sql文件
@sql文件,执行sql文件
*******************************************************
SQL> get e:\temp\report.sql
1 ttitle col 15 '我的报表' col 35 sql.pno
2 col deptno heading 部门号
3 col job heading 职位
4 col sum(sal) heading 工资总额
5* break on deptno skip 1
SQL> @e:\temp\report.sql
SQL> select deptno,job,sum(sal) from emp group by rollup(deptno,job);
我的报表 1
部门号 职位 工资总额
---------- --------- ----------
10 CLERK 1300
MANAGER 2450
PRESIDENT 5000
8750
20 CLERK 1900
ANALYST 6000
MANAGER 2975
10875
30 CLERK 950
MANAGER 2850
SALESMAN 5600
9400
29025
已选择13行。
SQL> set pagesize 10
SQL> select deptno,job,sum(sal) from emp group by rollup(deptno,job);
我的报表 1
部门号 职位 工资总额
---------- --------- ----------
10 CLERK 1300
MANAGER 2450
PRESIDENT 5000
8750
20 CLERK 1900
我的报表 2
部门号 职位 工资总额
---------- --------- ----------
20 ANALYST 6000
MANAGER 2975
10875
30 CLERK 950
MANAGER 2850
我的报表 3
部门号 职位 工资总额
---------- --------- ----------
30 SALESMAN 5600
9400
29025
已选择13行。
1.ttitle col 15 '我的报表' col 35 sql.pno
(使用ttitle命令设置报表的名称,col 15 表示空15个列,'我的报表'表示显示‘我的报表’,col 35 表示空35个列,sql.pno表示报表的页码)
2.col deptno heading 部门号
(使用col命令可以设置列的别名,将deptno heading '标题' 设置为别名'部门号')
3.break on deptno skip 1
(相同的部门号只显示一次,不同的部门号之间隔1行)
get:读取指定路径下的sql语句 @:执行指定路径下的sql语句 /:执行上一次SQL语句
sql plus报表功能
还能get 一个sql 不错嘛
然后@执行此处脚本
sql*plus的报表功能
报表包括:标题、页码、别名等
SELECT "AVG"(sal) avg_sal, "SUM"(sal) sun_sal, "MAX"(sal) max_sal, "MIN"(sal) min_sal, "COUNT"(empno) "count", "COUNT"(DISTINCT deptno) dept_count FROM emp;
SELECT deptno, wm_concat(ename) ename_list FROM emp GROUP BY deptno;
/**统计函数会过滤掉非空值**/
SELECT "SUM"(comm)/"COUNT"(*) avg_comm1, "SUM"(comm)/"COUNT"(comm) avg_comm2, "AVG"(comm) avg_comm3, "SUM"(comm)/"COUNT"("NVL"(comm, 0)) avg_comm4 from emp;
/** 求出各部门的平均工资 ORDER BY 可以跟一个数字,表示select中第几列的字段 **/
SELECT deptno, "AVG"(sal) from emp GROUP BY deptno, 2;
/** 求各部门不同职位的平均工资 **/
SELECT deptno, job, "AVG"(sal) avg_sal FROM emp GROUP BY deptno, job ORDER BY deptno;
/** 求平均工资大于2000元的部门 **/
SELECT deptno, "AVG"(sal) avg_sal FROM emp GROUP BY deptno HAVING "AVG"(sal) > 2000;
/** GROUP BY 增强 **/
SELECT deptno, job, "SUM"(sal) sum_sal FROM emp GROUP BY rollup(deptno,job);
get d:\temp\report.sql
ttitle col 15 '我的报表' col 35 sql.pno
col deptno heading 部门号
col job heading 职位
col sum(sal) heading 工资总额
break on deptno skip 1
@d:\temp\report.sql
select deptno,job,sum(sal) from emp group by rollup(deptno,job);
set pagesize 10
设置报表样式
ttitle col 15 '我的报表' col 35 sql.pno
*ttitle col 15表示空15列展示报表名称
*“我的报表”是报表名称
* sql.pno表示报表页码
col deptno heading 部门号
col job heading 职位
col sum(sal) heading 工资总额
break on deptno skip 1
*把以上设置放在.sql的文件下
在终端用get语句读取
@+路径执行脚本
执行select deptno, job, sum(sal) from emp group by rollup(deptno,job);
读取执行电脑文件
get 磁盘名称:\...\... .sql
@磁盘名称:\...\... .sql
报表
ttile col 15 ‘我的报表’col 35 sql.pno【空15列写标题,空35列显示报表页码】
col xxx1 heading xxx2;【为第xxx1列设置别名xxx2】
ttitle col 15 '我的报表' col 35 sql.pno
col deptno heading 部门号
col job heading 职位
col sum(sal) heading 工资总额
break on deptno skip 1
分析:ttitle 设置报表的名称,sql.pno表示报表的页码,col 15和col 35分别表示空15列和空35列
col 也能设置列的别名,heading表示标题