前言 课前补充知识
Number(p,s)
Number(p,s):数字类型,p 表示数字的有效长度(从数字的左边第 1 位不为 0
的開始算起,直到最右边的长度。取值范围 0~38 位),s 表示数字的精度(即小数点右边的位数,取值范围-84~127 位);
Varchar2(s)
Varchar2(s):可变长的字符类型。s 表示字符串的长度。取值范围 1~4000 位;
Char(s)
Char(s):定长的字符类型。s 表示字符串的长度,取值范围 1~2000 位。
Date
Date:时间类型。表示时间的年月日,没有长度和精度。取值范围公元前 4713 年 12 月 31 日~公元后 9999 年 12 月 31 日
1 sav 命令使用
1.1 用 sav 命令保存文件内容
TYGER@ORCL>create table t as select * from user_tables;
Table created.
TYGER@ORCL>select count(*) from t;
COUNT(*)
----------
11
TYGER@ORCL>sav /home/oracle/sel_t.sql
Created file /home/oracle/sel_t.sql
TYGER@ORCL>!
[oracle@tyger ~]$ ls
sel_t.sql
[oracle@tyger ~]$ cat sel_t.sql
select count(*) from t
/
[oracle@tyger ~]$
1.2 覆盖内容 sav filename rep
TYGER@ORCL>l
1* select * from t order by 1
TYGER@ORCL>sav /home/oracle/sel_t.sql rep
Wrote file /home/oracle/sel_t.sql
TYGER@ORCL>!
[oracle@tyger ~]$ cat sel_t.sql
select * from t order by 1
/
[oracle@tyger ~]$
1.3 追加内容 sav filename app
[oracle@tyger ~]$ cat sel_t.sql
select * from t order by 1
/
[oracle@tyger ~]$ exit
exit
TYGER@ORCL>select count(*) from t;
COUNT(*)
----------
11
TYGER@ORCL>sav /home/oracle/sel_t.sql app
Appended file to /home/oracle/sel_t.sql
TYGER@ORCL>!
[oracle@tyger ~]$
[oracle@tyger ~]$ cat sel_t.sql
select * from t order by 1
/
select count(*) from t
/
[oracle@tyger ~]$
2. spool 命令使用
spool on 表示将缓存打开。不然仅仅能保存近期运行的1条命令。
spool filename 表示将缓存中出现的命令以及结果输出到某个文件里;
spool off 表示关闭缓存,同一时候文件会自己主动保存;
[oracle@tyger ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jun 18 13:52:25 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SYS@ORCL>spool /home/oracle/sel_emp.sql
SYS@ORCL>conn scott/tiger;
Connected.
SCOTT@ORCL>select empno,ename from emp;
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
EMPNO ENAME
---------- ----------
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SCOTT@ORCL>spool off;
SCOTT@ORCL>exit
[oracle@tyger ~]$ cat sel_emp.sql
SYS@ORCL>conn scott/tiger;
Connected.
SCOTT@ORCL>select empno,ename from emp;
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
EMPNO ENAME
---------- ----------
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SCOTT@ORCL>spool off;
[oracle@tyger ~]$
Number(p,s)
Number(p,s):数字类型,p 表示数字的有效长度(从数字的左边第 1 位不为 0
的開始算起,直到最右边的长度。取值范围 0~38 位),s 表示数字的精度(即小数点右边的位数,取值范围-84~127 位);
Varchar2(s)
Varchar2(s):可变长的字符类型。s 表示字符串的长度。取值范围 1~4000 位;
Char(s)
Char(s):定长的字符类型。s 表示字符串的长度,取值范围 1~2000 位。
Date
Date:时间类型。表示时间的年月日,没有长度和精度。取值范围公元前 4713 年 12 月 31 日~公元后 9999 年 12 月 31 日
1 sav 命令使用
1.1 用 sav 命令保存文件内容
TYGER@ORCL>create table t as select * from user_tables;
Table created.
TYGER@ORCL>select count(*) from t;
COUNT(*)
----------
11
TYGER@ORCL>sav /home/oracle/sel_t.sql
Created file /home/oracle/sel_t.sql
TYGER@ORCL>!
[oracle@tyger ~]$ ls
sel_t.sql
[oracle@tyger ~]$ cat sel_t.sql
select count(*) from t
/
[oracle@tyger ~]$
1.2 覆盖内容 sav filename rep
TYGER@ORCL>l
1* select * from t order by 1
TYGER@ORCL>sav /home/oracle/sel_t.sql rep
Wrote file /home/oracle/sel_t.sql
TYGER@ORCL>!
[oracle@tyger ~]$ cat sel_t.sql
select * from t order by 1
/
[oracle@tyger ~]$
1.3 追加内容 sav filename app
[oracle@tyger ~]$ cat sel_t.sql
select * from t order by 1
/
[oracle@tyger ~]$ exit
exit
TYGER@ORCL>select count(*) from t;
COUNT(*)
----------
11
TYGER@ORCL>sav /home/oracle/sel_t.sql app
Appended file to /home/oracle/sel_t.sql
TYGER@ORCL>!
[oracle@tyger ~]$
[oracle@tyger ~]$ cat sel_t.sql
select * from t order by 1
/
select count(*) from t
/
[oracle@tyger ~]$
2. spool 命令使用
spool on 表示将缓存打开。不然仅仅能保存近期运行的1条命令。
spool filename 表示将缓存中出现的命令以及结果输出到某个文件里;
spool off 表示关闭缓存,同一时候文件会自己主动保存;
[oracle@tyger ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jun 18 13:52:25 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SYS@ORCL>spool /home/oracle/sel_emp.sql
SYS@ORCL>conn scott/tiger;
Connected.
SCOTT@ORCL>select empno,ename from emp;
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
EMPNO ENAME
---------- ----------
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SCOTT@ORCL>spool off;
SCOTT@ORCL>exit
[oracle@tyger ~]$ cat sel_emp.sql
SYS@ORCL>conn scott/tiger;
Connected.
SCOTT@ORCL>select empno,ename from emp;
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
EMPNO ENAME
---------- ----------
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SCOTT@ORCL>spool off;
[oracle@tyger ~]$