SQL> define sal = 4400 SQL> select * from employees 2 where salary = &sal 3 /
d。 使用accept命令定义变量,并且定制一个用户提示。定义是可以明确指定变量类型。
acc[ept] variable [data_type][for[mat] format] [def[ault] default] [prompt text|nopr[ompt]][hide] SQL> accept test char prompt 'Hi, you are required first_name which is ' Hi, you are required first_name which is 'Put' SQL> select * from employees where first_name = &test; 原值 1: select * from employees where first_name = &test 新值 1: select * from employees where first_name = 'Put'
column column_name for[mat] format option选项: for[mat] format 将列或列名的显示格式设置为由format字符串指定的格式。 hea[ding] text 设置有text支付指定的列标题。 jus[tify] [{left|center|right}] 将列的输出信息左对齐、居中和右对齐。
11. pagesize 命令设置一页显示多少行数据,从而控制每一页显示数据量。 set pagesize n (n 表示每一页大小的正整数,最大是50000,默认值是14) 页并不是仅仅由输出的数据行构成,而是sql*plus显示到屏幕上所有结果构成,包含标题和空行等。
12. linesize 命令 设置一行数据可以容纳的字符数量,默认数量是80. 如果linesize值较小,那么一行数据可能需要多行显示。 set linesize n (n表示屏幕上一行数据可以容纳的字符数量,有效范围是1 - 32767) set pagesize 100; set linesize 5678; column employee_id justify center; column manager_id jus center; column department_id jus center; select * from employees;
13. 创建简单报表。 a 使用tti[tle] [printspec [text|variable]...]|[off|on] 设置出现在每一个页面顶端的页眉。 printspec 的可选值有left,centere,right,bold,format text,col n, s[kip][n]和tab n. on 选项表示启用设置;off表示取消设置。 还可带有用户变量(内容有系统维护),如sql.pno页号,sql.lno行号等。
b. 使用bti[tle] [printspec[text|variable]..]]|[on|off] 指定出现在报表中每一页面底部的页脚。 c. 最后需要记得使用命名tti/btti off 关闭。 SQL> ttitle left 'Date: ' _date center 'Query data from employees' right 'Page: ' format 999 skip 2 sql.pnd SQL> btitle center 'Thank you for viewing this report' SQL> set echo off SQL> set verify off SQL> set pagesize 50 SQL> set linesize 5000 SQL> column employee_id heading 'emp_no' format 9999 SQL> column salary heading 'sal' format L99,999.99 SQL> column job_id justify center SQL> column department_id justify center SQL> select * from employees;
14. 计算小计break以及compute命令。 bre[ak] [on column_name] skip n a.column_name 表示对哪一列执行操作。 b.skip n表示在指定列的值变化之前插入n个空行。 comp[ute] function lable lable_text of column on a.表示执行的操作,例如sum/avg/count等。 b. lable 指定显示结果是的文本信息。
break on deptno 表示根据deptno进行分组。 compute sum of salary on deptno 表示根据员工所在部门分组,再求工资之和。 SQL> set pagesize 100; SQL> set linesize 5000; SQL> break on department_id; SQL> compute sum of salary on department_id; SQL> select * from employees;