【Oracle学习13】 实例管理

【Oracle学习13】 实例管理

13.1 使用数据库管理工具

Oracle Database Management Tools

13.1.1 SQL*PLUS

SQL and SQL*Plus Interaction
SQL*Plus Editing Commands
SQL*Plus File Commands
Using the SQL*Plus SPOOL Command
Using the AUTOTRACE Command

lrwrp:
可以改进sqlplus使用体验。

#配置epel源
vim epel.repo 
[aliyun_epel]   #这是Redhat的扩展包
name=ailiyun_yum_epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/x86_64
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
gpgcheck=0

yum install rlwrap  -y
#切换到oracle用户权限
su - oracle
vim  ~/.bash_profile 
alias sqlplus="rlwrap sqlplus"
alias rman="rlwrap rman"
alias ggsci="rlwrap ggsci"
#生效
source ~/.bash_profile 
#测试  alias

SQLPLUS使用:

  • 帮助
sqlplus [username[/password[@database]]]
SQL> help index
@             COPY         PASSWORD                 SHOW
@@            DEFINE       PAUSE                    SHUTDOWN
/             DEL          PRINT                    SPOOL

#查看表结构
DESC[RIBE] tablename
  • 执行脚本
$vim test.sql
select * from hr.departments where location_id = 1400;
quit
$sqlplus hr/hr @test.sql
  • 执行命令
#编辑SQL
SQL> select FIRST_NAME,last_name
  2   from employees
  3  where employee_id=113;
FIRST_NAME LAST_NAME
--------------------------------------------------
Luis Popp

SQL> 3
  3* where employee_id=113
SQL> change /113/100
  3* where employee_id=100

SQL> list
  1  select FIRST_NAME,last_name
  2   from employees
  3* where employee_id=100
SQL>/ 执行
FIRST_NAME LAST_NAME
--------------------------------------------------
Steven King

#保留
SQL> save /home/oracle/temp.sql
Created file /home/oracle/temp.sql
SQL> !ls -l /home/oracle/temp.sql
SQL> !cat /home/oracle/temp.sql
select EMPLOYEE_ID,first_name,last_name from employees where EMPLOYEE_ID=100
/
#读取文件
SQL> get /home/oracle/temp.sql
  1* select EMPLOYEE_ID,first_name,last_name from employees where EMPLOYEE_ID=100
#执行文件
SQL> start temp.sql
EMPLOYEE_ID FIRST_NAME LAST_NAME
--------------------------------------------------
100 Steven King
SQL> @temp.sql    --相同于start temp.sql

#编辑
SQL> edit 
Wrote file afiedt.buf
select EMPLOYEE_ID,first_name,last_name from employees where EMPLOYEE_ID=200
/
qw
SQL>/ 执行
  • Spool
SQL> spool spool_op.txt
SQL> select EMPLOYEE_ID,first_name from employees where EMPLOYEE_ID=200;
EMPLOYEE_ID FIRST_NAME
----------- ----------------------------------------
        200 Jennifer

SQL> c /200/100
  1* select EMPLOYEE_ID,first_name from employees where EMPLOYEE_ID=100
SQL> /
EMPLOYEE_ID FIRST_NAME
----------- ----------------------------------------
        100 Steven

SQL> spool off
SQL> !cat spool_op.txt
  • AUTOTRACE
语法: SET AUTOT[RACE] {ON | OFF | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
SQL> SET AUTOTRACE ON
Execution Plan
----------------------------------------------------------
Plan hash value: 1833546154

---------------------------------------------------------------------------------------------
| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |               |     1 |    11 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMPLOYEES     |     1 |    11 |     1   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN         | EMP_EMP_ID_PK |     1 |       |     0   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access("EMPLOYEE_ID"=200)

Statistics
----------------------------------------------------------
        173  recursive calls
          0  db block gets
        248  consistent gets
          0  physical reads
          0  redo size
        626  bytes sent via SQL*Net to client

#关闭
SQL> set AUTOTRACE off
  • 格式化
SQL> set lines 200  --即set linesize 200
SQL> set pagesize 200
SQL> desc v$parameter;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 NUM                                                NUMBER
 NAME                                               VARCHAR2(80)
 TYPE                                               NUMBER
 VALUE                                              VARCHAR2(4000)
 DISPLAY_VALUE                                      VARCHAR2(4000)
 DEFAULT_VALUE                                      VARCHAR2(255)
#如下会特别乱
SQL> Select name, type,value,isdefault from v$parameter where name ='db_file_multiblock_read_count'; --会特别乱

# 设置格式
Col name format a30
Col type for 9
Col value for a20
Set line size 150;
SQL>  Select name, type,value,isdefault from v$parameter where name ='db_file_multiblock_read_count';
NAME                           TYPE VALUE                ISDEFAULT
------------------------------ ---- -------------------- ------------------
db_file_multiblock_read_count     3 128                  TRUE

# 取消格式化 
SQL> clear col
columns cleared

13.1.3 使用Database Express

exec DBMS_XDB.setHTTPPort(5500)
netstat -lntp |grep 5500

你可能感兴趣的:(【Oracle学习13】 实例管理)