SQL*Plus小技巧
1,SQL*Plus命令绑定变量操作
SQL> var job varchar2(20)
SQL> exec :job :='SH_CLERK'
PL/SQL procedure successfully completed.
SQL> select job_id,employee_id from emp where job_id =:job;
SQL> print job
JOB
--------------------------------------------
SH_CLERK
2,显示行和页变量的大小
SQL> SHOW linesize pagesize
linesize 80
pagesize 14
3,设置每行显示80字符,每页显示26行
SQL> set linesize 80 pagesize 26
4,设置“&”字符的输入
在SQL*Plus默认环境里会把'&字符'当成变量来处理,有些时候也需要在SQL>的符号下输入'&字符',只需要改变SQL*Plus下一个环境变量define即可。
查看当前SQL*Plus的define状态:
SQL> SHOW define;
把默认的&绑定变量的功能取消,可以把'&字符'当成普通字符处理。
SQL> SET define off;
打开&绑定变量的功能,&后面的字符串当做变量使用。
SQL> SET define on;
5,设置列之间的分隔符
SQL> show colsep
colsep " "
SQL> select employee_id,job_id from emp where rownum<4;
EMPLOYEE_ID JOB_ID
----------- ----------
198 SH_CLERK
199 SH_CLERK
200 AD_ASST
SQL> set colsep |
SQL> show colsep
colsep "|"
SQL> select employee_id,job_id from emp where rownum<4;
EMPLOYEE_ID|JOB_ID
-----------|----------
198|SH_CLERK
199|SH_CLERK
200|AD_ASST
6,设置是否显示列标题
SQL> show heading
heading ON
SQL> set heading off
SQL> select employee_id,job_id from emp where rownum<4;
198|SH_CLERK
199|SH_CLERK
200|AD_ASST
SQL> set heading on
SQL> select employee_id,job_id from emp where rownum<4;
EMPLOYEE_ID|JOB_ID
-----------|----------
198|SH_CLERK
199|SH_CLERK
200|AD_ASST
7,设置系统时间显示
SQL> set time on
04:17:13 SQL>
SQL>set timing on
显示SQL语句的执行时间
8,把设置好的SQL环境变量值全部保存在一个脚本文件里
SQL> store set /home/oracle/myScripts/sqlset.sql
Created file /home/oracle/myScripts/sqlset.sql
9,Oracle的FORMAT用法
SQL> col job_id format a20
SQL> col salary format 9999999.99
SQL> select department_id,job_id,salary from emp where rownum<2;
DEPARTMENT_ID JOB_ID SALARY
------------- -------------------- -----------
50 SH_CLERK 2600.00