SQL>
SQL>
SQL> select * from t;
EMPNO ENAME SAL
---------- ---------- ----------
7369 SMITH 800
7499 ALLEN 1600
7521 WARD 1250
7566 JONES 2975
7654 MARTIN 1250
7698 BLAKE 2850
7782 CLARK 2450
7788 SCOTT 3000
7839 KING 5000
7844 TURNER 1500
7876 ADAMS 1100
EMPNO ENAME SAL
---------- ---------- ----------
7900 JAMES 950
7902 FORD 3000
7934 MILLER 1300
已选择14行。
SQL> set autotrace trace exp
SQL> select ename from t where ename='KING';
执行计划
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 7 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T | 1 | 7 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ENAME"='KING')
Note
-----
- dynamic sampling used for this statement
SQL> select ename from t order by ename;
执行计划
----------------------------------------------------------
Plan hash value: 961378228
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 98 | 4 (25)| 00:00:01 |
| 1 | SORT ORDER BY | | 14 | 98 | 4 (25)| 00:00:01 |
| 2 | TABLE ACCESS FULL| T | 14 | 98 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
SQL> create index t_idx on t(ename);
索引已创建。
SQL> analyze table t compute statistics;
表已分析。
SQL> select ename from t where ename='KING';
执行计划
----------------------------------------------------------
Plan hash value: 2946670127
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 5 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| T_IDX | 1 | 5 | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("ENAME"='KING')
SQL> select * from t where ename='KING';
执行计划
----------------------------------------------------------
Plan hash value: 470836197
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00
:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 11 | 2 (0)| 00:00
:01 |
|* 2 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:00
:01 |
--------------------------------------------------------------------------------
-----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ENAME"='KING')
SQL> select * from t where ename='KING' order by ename;
执行计划
----------------------------------------------------------
Plan hash value: 470836197
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00
:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 11 | 2 (0)| 00:00
:01 |
|* 2 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:00
:01 |
--------------------------------------------------------------------------------
-----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ENAME"='KING')
SQL> select * from t where ename='KING' order by ename desc;
执行计划
----------------------------------------------------------
Plan hash value: 470836197
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00
:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 11 | 2 (0)| 00:00
:01 |
|* 2 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:00
:01 |
--------------------------------------------------------------------------------
-----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ENAME"='KING')
SQL> select ename from t where ename='KING';
执行计划
----------------------------------------------------------
Plan hash value: 2946670127
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 5 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| T_IDX | 1 | 5 | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("ENAME"='KING')
SQL> ed
已写入 file afiedt.buf
1 select --+index_ffs(t)
2* ename from t where ename='KING'
SQL> /
执行计划
----------------------------------------------------------
Plan hash value: 3163761342
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 5 | 2 (0)| 00:00:01 |
|* 1 | INDEX FAST FULL SCAN| T_IDX | 1 | 5 | 2 (0)| 00:00:01 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ENAME"='KING')
SQL> conn / as sysdba
已连接。
SQL>
SQL>
SQL>
SQL> desc v$sysstat
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
STATISTIC# NUMBER
NAME VARCHAR2(64)
CLASS NUMBER
VALUE NUMBER
STAT_ID NUMBER
SQL>
SQL>
SQL>
SQL>
SQL> select name,value from v$sysstat where name like '%table scan%';
NAME VALUE
---------------------------------------------------------------- ----------
table scans (short tables) 5810
table scans (long tables) 0
table scans (rowid ranges) 0
table scans (cache partitions) 0
table scans (direct read) 0
table scan rows gotten 3946720
table scan blocks gotten 36528
已选择7行。
SQL>
SQL> select name,value from v$sysstat where name like '%sort%';
NAME VALUE
---------------------------------------------------------------- ----------
sorts (memory) 14957
sorts (disk) 0
sorts (rows) 134753
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> create table tt(x number,y number0;
create table tt(x number,y number0
*
第 1 行出现错误:
ORA-00907: 缺失右括号
SQL> create table tt(x number,y number);
表已创建。
SQL> insert into tt values(1,1);
已创建 1 行。
SQL> insert into tt values(2,2);
已创建 1 行。
SQL> insert into tt values(3,3);
已创建 1 行。
SQL> insert into tt values(1,1);
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
X Y
---------- ----------
10 10
10 10
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
X Y
---------- ----------
10 10
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
已选择22行。
SQL> select * from tt;
X Y
---------- ----------
1 1
2 2
3 3
1 1
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> select dname,ename,sal from emp ,dept where emp.deptno=dept.deptno
2 and emp.sal>=2000;
select dname,ename,sal from emp ,dept where emp.deptno=dept.deptno
*
第 1 行出现错误:
ORA-00942: 表或视图不存在
SQL>
SQL>
SQL>
SQL> conn scott/tiger
已连接。
SQL> select dname,ename,sal from emp ,dept where emp.deptno=dept.deptno
2 and emp.sal>=2000;
DNAME ENAME SAL
-------------- ---------- ----------
RESEARCH JONES 2975
SALES BLAKE 2850
ACCOUNTING CLARK 2450
RESEARCH SCOTT 3000
ACCOUNTING KING 5000
RESEARCH FORD 3000
已选择6行。
SQL> set autotrace trace exp
SQL> select dname,ename,sal from emp ,dept where emp.deptno=dept.deptno
2 and emp.sal>=2000;
执行计划
----------------------------------------------------------
Plan hash value: 351108634
--------------------------------------------------------------------------------
--------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Ti
me |
--------------------------------------------------------------------------------
--------
| 0 | SELECT STATEMENT | | 11 | 275 | 4 (0)| 00
:00:01 |
| 1 | NESTED LOOPS | | 11 | 275 | 4 (0)| 00
:00:01 |
|* 2 | TABLE ACCESS FULL | EMP | 11 | 132 | 3 (0)| 00
:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 13 | 1 (0)| 00
:00:01 |
|* 4 | INDEX UNIQUE SCAN | PK_DEPT | 1 | | 0 (0)| 00
:00:01 |
--------------------------------------------------------------------------------
--------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("EMP"."SAL">=2000)
4 - access("EMP"."DEPTNO"="DEPT"."DEPTNO")
SQL>
SQL>
SQL>
SQL>
SQL> desc emp
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
SQL>
SQL>
SQL> desc dept
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
DEPTNO NOT NULL NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
SQL>
SQL>
SQL>
SQL> select d.deptno,d.dname,sum(e.sal)
2 from dept d,emp e
3 where d.deptno=e.deptno
4 group by d.deptno,d.dname;
执行计划
----------------------------------------------------------
Plan hash value: 1457479512
--------------------------------------------------------------------------------
---------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| T
ime |
--------------------------------------------------------------------------------
---------
| 0 | SELECT STATEMENT | | 9 | 180 | 5 (20)| 0
0:00:01 |
| 1 | HASH GROUP BY | | 9 | 180 | 5 (20)| 0
0:00:01 |
| 2 | NESTED LOOPS | | 14 | 280 | 4 (0)| 0
0:00:01 |
| 3 | TABLE ACCESS FULL | EMP | 14 | 98 | 3 (0)| 0
0:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 13 | 1 (0)| 0
0:00:01 |
|* 5 | INDEX UNIQUE SCAN | PK_DEPT | 1 | | 0 (0)| 0
0:00:01 |
--------------------------------------------------------------------------------
---------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - access("D"."DEPTNO"="E"."DEPTNO")
SQL> set autotrace off
SQL> /
DEPTNO DNAME SUM(E.SAL)
---------- -------------- ----------
10 ACCOUNTING 8750
20 RESEARCH 10875
30 SALES 9400
SQL> ed
已写入 file afiedt.buf
1 select d.deptno,d.dname,sum(e.sal)
2 from dept d,emp e
3 where d.deptno=e.deptno
4* group by d.deptno,d.dname
SQL> select empno,ename,sal from emp;
EMPNO ENAME SAL
---------- ---------- ----------
7369 SMITH 800
7499 ALLEN 1600
7521 WARD 1250
7566 JONES 2975
7654 MARTIN 1250
7698 BLAKE 2850
7782 CLARK 2450
7788 SCOTT 3000
7839 KING 5000
7844 TURNER 1500
7876 ADAMS 1100
EMPNO ENAME SAL
---------- ---------- ----------
7900 JAMES 950
7902 FORD 3000
7934 MILLER 1300
已选择14行。
SQL> select * from salgrade;
GRADE LOSAL HISAL
---------- ---------- ----------
1 700 1200
2 1201 1400
3 1401 2000
4 2001 3000
5 3001 9999
SQL> select e.empno,e.name.e.sal,s.grade
2 from emp e,salgrade s
3 where e.sal between s.losal and s.hisal;
select e.empno,e.name.e.sal,s.grade
*
第 1 行出现错误:
ORA-00904: "E"."NAME"."E"."SAL": 标识符无效
SQL> select e.empno,e.name.e.sal,s.grade
2 from emp e,salgrade s
3 where e.sal between s.losal and s.hisal;
select e.empno,e.name.e.sal,s.grade
*
第 1 行出现错误:
ORA-00904: "E"."NAME"."E"."SAL": 标识符无效
SQL> ed
已写入 file afiedt.buf
1 select e.empno,e.ename.e.sal,s.grade
2 from emp e,salgrade s
3* where e.sal between s.losal and s.hisal
SQL> /
select e.empno,e.ename.e.sal,s.grade
*
第 1 行出现错误:
ORA-00904: "E"."ENAME"."E"."SAL": 标识符无效
SQL> ed
已写入 file afiedt.buf
1 select e.empno,e.ename,e.sal,s.grade
2 from emp e,salgrade s
3* where e.sal between s.losal and s.hisal
SQL> /
EMPNO ENAME SAL GRADE
---------- ---------- ---------- ----------
7369 SMITH 800 1
7900 JAMES 950 1
7876 ADAMS 1100 1
7521 WARD 1250 2
7654 MARTIN 1250 2
7934 MILLER 1300 2
7844 TURNER 1500 3
7499 ALLEN 1600 3
7782 CLARK 2450 4
7698 BLAKE 2850 4
7566 JONES 2975 4
EMPNO ENAME SAL GRADE
---------- ---------- ---------- ----------
7788 SCOTT 3000 4
7902 FORD 3000 4
7839 KING 5000 5
已选择14行。
SQL> seelct * from dept;
SP2-0734: 未知的命令开头 "seelct * f..." - 忽略了剩余的行。
SQL> select * from dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> select empno,ename,sal,deptno from emp;
EMPNO ENAME SAL DEPTNO
---------- ---------- ---------- ----------
7369 SMITH 800 20
7499 ALLEN 1600 30
7521 WARD 1250 30
7566 JONES 2975 20
7654 MARTIN 1250 30
7698 BLAKE 2850 30
7782 CLARK 2450 10
7788 SCOTT 3000 20
7839 KING 5000 10
7844 TURNER 1500 30
7876 ADAMS 1100 20
EMPNO ENAME SAL DEPTNO
---------- ---------- ---------- ----------
7900 JAMES 950 30
7902 FORD 3000 20
7934 MILLER 1300 10
已选择14行。
SQL> select dname,ename,sal
2 from dept,emp
3 where dept.deptno=emp.deptno;
DNAME ENAME SAL
-------------- ---------- ----------
RESEARCH SMITH 800
SALES ALLEN 1600
SALES WARD 1250
RESEARCH JONES 2975
SALES MARTIN 1250
SALES BLAKE 2850
ACCOUNTING CLARK 2450
RESEARCH SCOTT 3000
ACCOUNTING KING 5000
SALES TURNER 1500
RESEARCH ADAMS 1100
DNAME ENAME SAL
-------------- ---------- ----------
SALES JAMES 950
RESEARCH FORD 3000
ACCOUNTING MILLER 1300
已选择14行。
SQL> ed
已写入 file afiedt.buf
1 select dept.deptno,dname,ename,sal
2 from dept,emp
3* where dept.deptno=emp.deptno
SQL> /
DEPTNO DNAME ENAME SAL
---------- -------------- ---------- ----------
20 RESEARCH SMITH 800
30 SALES ALLEN 1600
30 SALES WARD 1250
20 RESEARCH JONES 2975
30 SALES MARTIN 1250
30 SALES BLAKE 2850
10 ACCOUNTING CLARK 2450
20 RESEARCH SCOTT 3000
10 ACCOUNTING KING 5000
30 SALES TURNER 1500
20 RESEARCH ADAMS 1100
DEPTNO DNAME ENAME SAL
---------- -------------- ---------- ----------
30 SALES JAMES 950
20 RESEARCH FORD 3000
10 ACCOUNTING MILLER 1300
已选择14行。
SQL> ed
已写入 file afiedt.buf
1 select dept.deptno,dname,ename,sal
2 from dept,emp
3 where dept.deptno=emp.deptno
4* order by dept.deptno
SQL> /
DEPTNO DNAME ENAME SAL
---------- -------------- ---------- ----------
10 ACCOUNTING CLARK 2450
10 ACCOUNTING KING 5000
10 ACCOUNTING MILLER 1300
20 RESEARCH JONES 2975
20 RESEARCH FORD 3000
20 RESEARCH ADAMS 1100
20 RESEARCH SMITH 800
20 RESEARCH SCOTT 3000
30 SALES WARD 1250
30 SALES TURNER 1500
30 SALES ALLEN 1600
DEPTNO DNAME ENAME SAL
---------- -------------- ---------- ----------
30 SALES JAMES 950
30 SALES BLAKE 2850
30 SALES MARTIN 1250
已选择14行。
SQL> ed
已写入 file afiedt.buf
1 select dept.deptno,dname,ename,sal
2 from dept,emp
3 where dept.deptno=emp.deptno(+)
4* order by dept.deptno
SQL> /
DEPTNO DNAME ENAME SAL
---------- -------------- ---------- ----------
10 ACCOUNTING CLARK 2450
10 ACCOUNTING KING 5000
10 ACCOUNTING MILLER 1300
20 RESEARCH JONES 2975
20 RESEARCH FORD 3000
20 RESEARCH ADAMS 1100
20 RESEARCH SMITH 800
20 RESEARCH SCOTT 3000
30 SALES WARD 1250
30 SALES TURNER 1500
30 SALES ALLEN 1600
DEPTNO DNAME ENAME SAL
---------- -------------- ---------- ----------
30 SALES JAMES 950
30 SALES BLAKE 2850
30 SALES MARTIN 1250
40 OPERATIONS
已选择15行。
SQL> select empno,ename,sal,mgr from emp;
EMPNO ENAME SAL MGR
---------- ---------- ---------- ----------
7369 SMITH 800 7902
7499 ALLEN 1600 7698
7521 WARD 1250 7698
7566 JONES 2975 7839
7654 MARTIN 1250 7698
7698 BLAKE 2850 7839
7782 CLARK 2450 7839
7788 SCOTT 3000 7566
7839 KING 5000
7844 TURNER 1500 7698
7876 ADAMS 1100 7788
EMPNO ENAME SAL MGR
---------- ---------- ---------- ----------
7900 JAMES 950 7698
7902 FORD 3000 7566
7934 MILLER 1300 7782
已选择14行。
SQL> select w.ename ||' report for '||m.ename
2 from emp w,emp m
3 where w.mgr=m.empno;
W.ENAME||'REPORTFOR'||M.ENAME
--------------------------------
SMITH report for FORD
ALLEN report for BLAKE
WARD report for BLAKE
JONES report for KING
MARTIN report for BLAKE
BLAKE report for KING
CLARK report for KING
SCOTT report for JONES
TURNER report for BLAKE
ADAMS report for SCOTT
JAMES report for BLAKE
W.ENAME||'REPORTFOR'||M.ENAME
--------------------------------
FORD report for JONES
MILLER report for CLARK
已选择13行。
SQL> set pagesize 120
SQL> /
W.ENAME||'REPORTFOR'||M.ENAME
--------------------------------
SMITH report for FORD
ALLEN report for BLAKE
WARD report for BLAKE
JONES report for KING
MARTIN report for BLAKE
BLAKE report for KING
CLARK report for KING
SCOTT report for JONES
TURNER report for BLAKE
ADAMS report for SCOTT
JAMES report for BLAKE
FORD report for JONES
MILLER report for CLARK
已选择13行。
SQL> select ename ||' work for '|| prior ename
2 from emp
3 start with ename='KING'
4 connect by prior empno=mgr;
ENAME||'WORKFOR'||PRIORENAME
------------------------------
KING work for
JONES work for KING
SCOTT work for JONES
ADAMS work for SCOTT
FORD work for JONES
SMITH work for FORD
BLAKE work for KING
ALLEN work for BLAKE
WARD work for BLAKE
MARTIN work for BLAKE
TURNER work for BLAKE
JAMES work for BLAKE
CLARK work for KING
MILLER work for CLARK
已选择14行。
SQL>
SQL>
SQL>
SQL> create table d as select * from dept;
表已创建。
SQL> create table e as select * from emp;
表已创建。
SQL> select d.dname,e.ename,e.sal from d,e
2 where d.deptno=e.deptno;
DNAME ENAME SAL
-------------- ---------- ----------
RESEARCH SMITH 800
SALES ALLEN 1600
SALES WARD 1250
RESEARCH JONES 2975
SALES MARTIN 1250
SALES BLAKE 2850
ACCOUNTING CLARK 2450
RESEARCH SCOTT 3000
ACCOUNTING KING 5000
SALES TURNER 1500
RESEARCH ADAMS 1100
SALES JAMES 950
RESEARCH FORD 3000
ACCOUNTING MILLER 1300
已选择14行。
SQL> set autotrace trace exp
SQL> /
执行计划
----------------------------------------------------------
Plan hash value: 1127375450
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 770 | 7 (15)| 00:00:01 |
|* 1 | HASH JOIN | | 14 | 770 | 7 (15)| 00:00:01 |
| 2 | TABLE ACCESS FULL| D | 4 | 88 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| E | 14 | 462 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("D"."DEPTNO"="E"."DEPTNO")
Note
-----
- dynamic sampling used for this statement
SQL> ed
已写入 file afiedt.buf
1 select /*+use_nl(d e) */ d.dname,e.ename,e.sal from d,e
2* where d.deptno=e.deptno
SQL> /
执行计划
----------------------------------------------------------
Plan hash value: 2204556440
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 770 | 8 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 14 | 770 | 8 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL| D | 4 | 88 | 3 (0)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| E | 4 | 132 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("D"."DEPTNO"="E"."DEPTNO")
Note
-----
- dynamic sampling used for this statement
SQL> select d.dname,e.ename,e.sal from d,e
2 where d.deptno=e.deptno;
执行计划
----------------------------------------------------------
Plan hash value: 1127375450
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 770 | 7 (15)| 00:00:01 |
|* 1 | HASH JOIN | | 14 | 770 | 7 (15)| 00:00:01 |
| 2 | TABLE ACCESS FULL| D | 4 | 88 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| E | 14 | 462 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("D"."DEPTNO"="E"."DEPTNO")
Note
-----
- dynamic sampling used for this statement
SQL> ed
已写入 file afiedt.buf
1 select /*+ use_merge (d e) */ d.dname,e.ename,e.sal from d,e
2* where d.deptno=e.deptno
SQL> /
执行计划
----------------------------------------------------------
Plan hash value: 641922365
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 770 | 8 (25)| 00:00:01 |
| 1 | MERGE JOIN | | 14 | 770 | 8 (25)| 00:00:01 |
| 2 | SORT JOIN | | 4 | 88 | 4 (25)| 00:00:01 |
| 3 | TABLE ACCESS FULL| D | 4 | 88 | 3 (0)| 00:00:01 |
|* 4 | SORT JOIN | | 14 | 462 | 4 (25)| 00:00:01 |
| 5 | TABLE ACCESS FULL| E | 14 | 462 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("D"."DEPTNO"="E"."DEPTNO")
filter("D"."DEPTNO"="E"."DEPTNO")
Note
-----
- dynamic sampling used for this statement
SQL> desc v$sql
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
SQL_TEXT VARCHAR2(1000)
SQL_FULLTEXT CLOB
SQL_ID VARCHAR2(13)
SHARABLE_MEM NUMBER
PERSISTENT_MEM NUMBER
RUNTIME_MEM NUMBER
SORTS NUMBER
LOADED_VERSIONS NUMBER
OPEN_VERSIONS NUMBER
USERS_OPENING NUMBER
FETCHES NUMBER
EXECUTIONS NUMBER
PX_SERVERS_EXECUTIONS NUMBER
END_OF_FETCH_COUNT NUMBER
USERS_EXECUTING NUMBER
LOADS NUMBER
FIRST_LOAD_TIME VARCHAR2(38)
INVALIDATIONS NUMBER
PARSE_CALLS NUMBER
DISK_READS NUMBER
DIRECT_WRITES NUMBER
BUFFER_GETS NUMBER
APPLICATION_WAIT_TIME NUMBER
CONCURRENCY_WAIT_TIME NUMBER
CLUSTER_WAIT_TIME NUMBER
USER_IO_WAIT_TIME NUMBER
PLSQL_EXEC_TIME NUMBER
JAVA_EXEC_TIME NUMBER
ROWS_PROCESSED NUMBER
COMMAND_TYPE NUMBER
OPTIMIZER_MODE VARCHAR2(10)
OPTIMIZER_COST NUMBER
OPTIMIZER_ENV RAW(797)
OPTIMIZER_ENV_HASH_VALUE NUMBER
PARSING_USER_ID NUMBER
PARSING_SCHEMA_ID NUMBER
PARSING_SCHEMA_NAME VARCHAR2(30)
KEPT_VERSIONS NUMBER
ADDRESS RAW(4)
TYPE_CHK_HEAP RAW(4)
HASH_VALUE NUMBER
OLD_HASH_VALUE NUMBER
PLAN_HASH_VALUE NUMBER
CHILD_NUMBER NUMBER
SERVICE VARCHAR2(64)
SERVICE_HASH NUMBER
MODULE VARCHAR2(64)
MODULE_HASH NUMBER
ACTION VARCHAR2(64)
ACTION_HASH NUMBER
SERIALIZABLE_ABORTS NUMBER
OUTLINE_CATEGORY VARCHAR2(64)
CPU_TIME NUMBER
ELAPSED_TIME NUMBER
OUTLINE_SID NUMBER
CHILD_ADDRESS RAW(4)
SQLTYPE NUMBER
REMOTE VARCHAR2(1)
OBJECT_STATUS VARCHAR2(19)
LITERAL_HASH_VALUE NUMBER
LAST_LOAD_TIME VARCHAR2(38)
IS_OBSOLETE VARCHAR2(1)
CHILD_LATCH NUMBER
SQL_PROFILE VARCHAR2(64)
PROGRAM_ID NUMBER
PROGRAM_LINE# NUMBER
EXACT_MATCHING_SIGNATURE NUMBER
FORCE_MATCHING_SIGNATURE NUMBER
LAST_ACTIVE_TIME DATE
BIND_DATA RAW(2000)
SQL> col sql_text for a55
SQL> select sql_text,sql_id from v$sql
2 where sql_text like 'select * from%';
SQL_TEXT SQL_ID
------------------------------------------------------- -------------
select * from t 89km4qj1thh13
select * from t where ename='SMITH' cbck95sggdad4
select * from tt 91875rx53tmd0
select * from tab 767pug2dbpqpc
select * from dept 3154rqzb8xudy
select * from table(dbms_xplan.display) ff5spha9pjuyu
select * from salgrade 30p00zk91247c
已选择7行。
SQL> select * from table(dbms_xplan.display_cursor('cbck95sggdad4'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID cbck95sggdad4, child number 0
-------------------------------------
select * from t where ename='SMITH'
Plan hash value: 470836197
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | | | 2 (100)|
|
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 11 | 2 (0)| 00:00
:01 |
|* 2 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:00
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
:01 |
--------------------------------------------------------------------------------
-----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ENAME"='SMITH')
已选择19行。
SQL>
SQL>
SQL> show autotrace
autotrace OFF
SQL> set autorace
SP2-0158: 未知的 SET 选项 "autorace"
SQL> set autotrace
用法: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
SQL> set autotrace on
SQL> select * from t where ename='KING';
select * from t where ename='KING'
*
第 1 行出现错误:
ORA-00904: "ENAME": 标识符无效
SQL> select * from t where ename='KING';
select * from t where ename='KING'
*
第 1 行出现错误:
ORA-00904: "ENAME": 标识符无效
SQL>
SQL> conn scott/tiger
已连接。
SQL> set autotrace on
SP2-0618: 无法找到会话标识符。启用检查 PLUSTRACE 角色
SP2-0611: 启用 STATISTICS 报告时出错
SQL> set autotrace trace exp
SQL> set autotrace on
SP2-0618: 无法找到会话标识符。启用检查 PLUSTRACE 角色
SP2-0611: 启用 STATISTICS 报告时出错
SQL> conn / as sysdba
已连接。
SQL> grant plustrace to scott;
grant plustrace to scott
*
第 1 行出现错误:
ORA-01919: 角色 'PLUSTRACE' 不存在
SQL> @?/sqlplus/admin/plustrce.sql
SQL>
SQL> drop role plustrace;
drop role plustrace
*
第 1 行出现错误:
ORA-01919: 角色 'PLUSTRACE' 不存在
SQL> create role plustrace;
角色已创建。
SQL>
SQL> grant select on v_$sesstat to plustrace;
授权成功。
SQL> grant select on v_$statname to plustrace;
授权成功。
SQL> grant select on v_$mystat to plustrace;
授权成功。
SQL> grant plustrace to dba with admin option;
授权成功。
SQL>
SQL> set echo off
SQL> grant plustrace to scott;
授权成功。
SQL> conn scott/tiger
已连接。
SQL> set autotrace trace exp
SQL> set autotrace on
SQL> select * from t where ename='KING';
EMPNO ENAME SAL
---------- ---------- ----------
7839 KING 5000
执行计划
----------------------------------------------------------
Plan hash value: 470836197
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00
:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 11 | 2 (0)| 00:00
:01 |
|* 2 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:00
:01 |
--------------------------------------------------------------------------------
-----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ENAME"='KING')
统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
526 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace trace
SQL> /
执行计划
----------------------------------------------------------
Plan hash value: 470836197
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00
:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 11 | 2 (0)| 00:00
:01 |
|* 2 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:00
:01 |
--------------------------------------------------------------------------------
-----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ENAME"='KING')
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
526 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace trace exp
SQL> /
执行计划
----------------------------------------------------------
Plan hash value: 470836197
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00
:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 11 | 2 (0)| 00:00
:01 |
|* 2 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:00
:01 |
--------------------------------------------------------------------------------
-----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ENAME"='KING')
SQL> set autotrace trace stat
SQL> /
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
526 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> create table t as select empno,ename,sal from emp;
表已创建。
SQL> select table_name,num_rows
2 from user_tables
3 where table_name='T';
TABLE_NAME NUM_ROWS
------------------------------ ----------
T
SQL> analyze table t compute statistics;
表已分析。
SQL> select table_name,num_rows
2 from user_tables
3 where table_name='T';
TABLE_NAME NUM_ROWS
------------------------------ ----------
T 14
SQL> insert into t select * from t;
已创建14行。
SQL> commit;
提交完成。
SQL> select table_name,num_rows
2 from user_tables
3 where table_name='T';
TABLE_NAME NUM_ROWS
------------------------------ ----------
T 14
SQL> analyze table t estimate statistics;
表已分析。
SQL> analyze table t estimate statistics sample size 10 rows;
analyze table t estimate statistics sample size 10 rows
*
第 1 行出现错误:
ORA-01493: 指定的 SAMPLE 大小无效
SQL> analyze table t estimate statistics sample 10 rows;
表已分析。
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> analyze table t estimate statistics sample 15 percent;
表已分析。
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> select table_name,num_rows
2 from user_tables
3 where table_name='T';
TABLE_NAME NUM_ROWS
------------------------------ ----------
T 28
SQL> select ename from t where empno=7369;
ENAME
----------
SMITH
SMITH
SQL> select ename from t where empno=:b;
SP2-0552: 未声明绑定变量 "B"。
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> begin
2 execute immediate 'select ename from t where empno =:b';
3 end;
4 /
begin
*
第 1 行出现错误:
ORA-01008: 并非所有变量都已绑定
ORA-06512: 在 line 2
SQL> var b number;
SQL> begin
2 execute immediate 'select ename from t where empno =:b';
3 end;
4 /
begin
*
第 1 行出现错误:
ORA-01008: 并非所有变量都已绑定
ORA-06512: 在 line 2
SQL>
SQL>
SQL> create table t1 as select empno,ename,sal,deptno from emp;
表已创建。
SQL> select table_name,num_rows
2 from user_tables
3 where table_name='T1';
TABLE_NAME NUM_ROWS
------------------------------ ----------
T1
SQL> exec dbms_stats.gather_table_stats(user,'T1');
PL/SQL 过程已成功完成。
SQL> select user from dual;
USER
------------------------------
SCOTT
SQL> select table_name,num_rows
2 from user_tables
3 where table_name='T1';
TABLE_NAME NUM_ROWS
------------------------------ ----------
T1 14
SQL> exec dbms_stats.gather_table_stats(user,'T1',false);
BEGIN dbms_stats.gather_table_stats(user,'T1',false); END;
*
第 1 行出现错误:
ORA-06550: 第 1 行, 第 7 列:
PLS-00306: 调用 'GATHER_TABLE_STATS' 时参数个数或类型错误
ORA-06550: 第 1 行, 第 7 列:
PL/SQL: Statement ignored
SQL> exec dbms_stats.gather_table_stats(user,'T1',CASCADE=>false);
PL/SQL 过程已成功完成。
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> select table_name,num_rows
2 from user_tables
3 where table_name='T1';
TABLE_NAME NUM_ROWS
------------------------------ ----------
T1 14
SQL> desc index_stats
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
HEIGHT NUMBER
BLOCKS NUMBER
NAME VARCHAR2(30)
PARTITION_NAME VARCHAR2(30)
LF_ROWS NUMBER
LF_BLKS NUMBER
LF_ROWS_LEN NUMBER
LF_BLK_LEN NUMBER
BR_ROWS NUMBER
BR_BLKS NUMBER
BR_ROWS_LEN NUMBER
BR_BLK_LEN NUMBER
DEL_LF_ROWS NUMBER
DEL_LF_ROWS_LEN NUMBER
DISTINCT_KEYS NUMBER
MOST_REPEATED_KEY NUMBER
BTREE_SPACE NUMBER
USED_SPACE NUMBER
PCT_USED NUMBER
ROWS_PER_KEY NUMBER
BLKS_GETS_PER_ACCESS NUMBER
PRE_ROWS NUMBER
PRE_ROWS_LEN NUMBER
OPT_CMPR_COUNT NUMBER
OPT_CMPR_PCTSAVE NUMBER
SQL> alter session set sql_trace true;
会话已更改。
SQL> select ename,sal ,mgr from emp where rownum<=3;
ENAME SAL MGR
---------- ---------- ----------
SMITH 800 7902
ALLEN 1600 7698
WARD 1250 7698
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
DEPT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
T1 TABLE
T TABLE
已选择6行。
SQL> udpate t set ename='tom' where rownum=1;
SP2-0734: 未知的命令开头 "udpate t s..." - 忽略了剩余的行。
SQL> update t set ename='tom' where rownum=1;
已更新 1 行。
SQL> commit;
提交完成。
SQL> atler session set sql_trace false;
SP2-0734: 未知的命令开头 "atler sess..." - 忽略了剩余的行。
SQL> alter session set sql_trace false;
会话已更改。
SQL> conn scott/tiger
已连接。
SQL> conn / as sysdba
已连接。
SQL> select sid,serial#,username from v$session
2 where username != ' ';
SID SERIAL# USERNAME
---------- ---------- ------------------------------
128 72 SYSMAN
130 32 SYSMAN
136 2184 SYS
138 11 DBSNMP
140 3146 SCOTT
145 50 DBSNMP
158 691 SYSMAN
已选择7行。
SQL> select distinct sid from v$mystat;
SID
----------
136
SQL> desc dbms_system
PROCEDURE DIST_TXN_SYNC
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
INST_NUM NUMBER IN
PROCEDURE GET_ENV
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
VAR VARCHAR2 IN
VAL VARCHAR2 OUT
PROCEDURE KCFRMS
PROCEDURE KSDDDT
PROCEDURE KSDFLS
PROCEDURE KSDIND
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
LVL BINARY_INTEGER IN
PROCEDURE KSDWRT
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
DEST BINARY_INTEGER IN
TST VARCHAR2 IN
PROCEDURE READ_EV
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
IEV BINARY_INTEGER IN
OEV BINARY_INTEGER OUT
PROCEDURE SET_BOOL_PARAM_IN_SESSION
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
SID NUMBER IN
SERIAL# NUMBER IN
PARNAM VARCHAR2 IN
BVAL BOOLEAN IN
PROCEDURE SET_EV
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
SI BINARY_INTEGER IN
SE BINARY_INTEGER IN
EV BINARY_INTEGER IN
LE BINARY_INTEGER IN
NM VARCHAR2 IN
PROCEDURE SET_INT_PARAM_IN_SESSION
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
SID NUMBER IN
SERIAL# NUMBER IN
PARNAM VARCHAR2 IN
INTVAL BINARY_INTEGER IN
PROCEDURE SET_SQL_TRACE_IN_SESSION
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
SID NUMBER IN
SERIAL# NUMBER IN
SQL_TRACE BOOLEAN IN
PROCEDURE WAIT_FOR_EVENT
参数名称 类型 输入/输出默认值?
------------------------------ ----------------------- ------ --------
EVENT VARCHAR2 IN
EXTENDED_ID BINARY_INTEGER IN
TIMEOUT BINARY_INTEGER IN
SQL> exec dbms_system.SET_SQL_TRACE_IN_SESSION(140,3146,true);
PL/SQL 过程已成功完成。
SQL> exec dbms_system.SET_SQL_TRACE_IN_SESSION(140,3146,false);
PL/SQL 过程已成功完成。
SQL> show parameter user_dump_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest string E:/ORACLE/ADMIN/DB01/UDUMP
SQL> show parameter max_dum
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
max_dump_file_size string UNLIMITED
SQL>
SQL>