sql系列(基础篇)-前言 课前补充知识
Posted lxjshuju
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql系列(基础篇)-前言 课前补充知识相关的知识,希望对你有一定的参考价值。
前言 课前补充知识
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 命令保存文件内容
[email protected]>create table t as select * from user_tables;
Table created.
[email protected]>select count(*) from t;
COUNT(*)
----------
11
[email protected]>sav /home/oracle/sel_t.sql
Created file /home/oracle/sel_t.sql
[email protected]>!
[[email protected] ~]$ ls
sel_t.sql
[[email protected] ~]$ cat sel_t.sql
select count(*) from t
/
[[email protected] ~]$
1.2 覆盖内容 sav filename rep
[email protected]>l
1* select * from t order by 1
[email protected]>sav /home/oracle/sel_t.sql rep
Wrote file /home/oracle/sel_t.sql
[email protected]>!
[[email protected] ~]$ cat sel_t.sql
select * from t order by 1
/
[[email protected] ~]$
1.3 追加内容 sav filename app
[[email protected] ~]$ cat sel_t.sql
select * from t order by 1
/
[[email protected] ~]$ exit
exit
[email protected]>select count(*) from t;
COUNT(*)
----------
11
[email protected]>sav /home/oracle/sel_t.sql app
Appended file to /home/oracle/sel_t.sql
[email protected]>!
[[email protected] ~]$
[[email protected] ~]$ cat sel_t.sql
select * from t order by 1
/
select count(*) from t
/
[[email protected] ~]$
2. spool 命令使用
spool on 表示将缓存打开。不然仅仅能保存近期运行的1条命令。
spool filename 表示将缓存中出现的命令以及结果输出到某个文件里;
spool off 表示关闭缓存,同一时候文件会自己主动保存;
[[email protected] ~]$ 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
[email protected]>spool /home/oracle/sel_emp.sql
[email protected]>conn scott/tiger;
Connected.
[email protected]>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.
[email protected]>spool off;
[email protected]>exit
[[email protected] ~]$ cat sel_emp.sql
[email protected]>conn scott/tiger;
Connected.
[email protected]>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.
[email protected]>spool off;
[[email protected] ~]$
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 命令保存文件内容
[email protected]>create table t as select * from user_tables;
Table created.
[email protected]>select count(*) from t;
COUNT(*)
----------
11
[email protected]>sav /home/oracle/sel_t.sql
Created file /home/oracle/sel_t.sql
[email protected]>!
[[email protected] ~]$ ls
sel_t.sql
[[email protected] ~]$ cat sel_t.sql
select count(*) from t
/
[[email protected] ~]$
1.2 覆盖内容 sav filename rep
[email protected]>l
1* select * from t order by 1
[email protected]>sav /home/oracle/sel_t.sql rep
Wrote file /home/oracle/sel_t.sql
[email protected]>!
[[email protected] ~]$ cat sel_t.sql
select * from t order by 1
/
[[email protected] ~]$
1.3 追加内容 sav filename app
[[email protected] ~]$ cat sel_t.sql
select * from t order by 1
/
[[email protected] ~]$ exit
exit
[email protected]>select count(*) from t;
COUNT(*)
----------
11
[email protected]>sav /home/oracle/sel_t.sql app
Appended file to /home/oracle/sel_t.sql
[email protected]>!
[[email protected] ~]$
[[email protected] ~]$ cat sel_t.sql
select * from t order by 1
/
select count(*) from t
/
[[email protected] ~]$
2. spool 命令使用
spool on 表示将缓存打开。不然仅仅能保存近期运行的1条命令。
spool filename 表示将缓存中出现的命令以及结果输出到某个文件里;
spool off 表示关闭缓存,同一时候文件会自己主动保存;
[[email protected] ~]$ 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
[email protected]>spool /home/oracle/sel_emp.sql
[email protected]>conn scott/tiger;
Connected.
[email protected]>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.
[email protected]>spool off;
[email protected]>exit
[[email protected] ~]$ cat sel_emp.sql
[email protected]>conn scott/tiger;
Connected.
[email protected]>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.
[email protected]>spool off;
[[email protected] ~]$
以上是关于sql系列(基础篇)-前言 课前补充知识的主要内容,如果未能解决你的问题,请参考以下文章
机器学习|数学基础Mathematics for Machine Learning系列之矩阵理论(23):常数项级数的概念和性质(补充知识)
机器学习|数学基础Mathematics for Machine Learning系列之矩阵理论(19):不定积分(补充知识)
机器学习|数学基础Mathematics for Machine Learning系列之矩阵理论(25):幂级数(补充知识)
机器学习|数学基础Mathematics for Machine Learning系列之矩阵理论(25):幂级数(补充知识)