sqlplus基本操作

1)登入/出数据库
[oracle@ocmserver]sqlplus jack/tiger@ibm      -----账户jack,密码tiger,数据库实例ibm

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Nov 24 23:38:42 2012

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

SQL> show user;            ----现实当前账号是谁
USER is "JACK"
SQL> disc                     ----退出会话连接,完整写法是disconnect
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>exit                      ----退出sqlplus
2)查询之前的相关设置
1.不设置查询结果格式为:
SQL> select * from tab;

TNAME                                                                                                                TABTYPE
------------------------------------------------------------ --------------
CLUSTERID
----------
WLAN_FUTURE_EVENT                                                                                        TABLE


EMPLOYEES                                                                                                        TABLE


EMP_SAL2                                                                                                         VIEW



TNAME                                                                                                                TABTYPE
------------------------------------------------------------ --------------
CLUSTERID
----------
P1                                                                                                                     TABLE


P2                                                                                                                     TABLE


P3                                                                                                                     TABLE



6 rows selected.

SQL>
----------------------------
2.设置后查询结果
SQL> set line 300            ----设置行大小,完整写法为set linesize 300
SQL> set pages 9000       ----设置页大小,完整写法为set pagesize 9000
SQL> set timing on          ----开启查询时间显示,查询结果会现在此次查询耗时,如Elapsed:00:00:00.02
SQL> select * from tab;

TNAME                                                                                                                TABTYPE                 CLUSTERID
------------------------------------------------------------ -------------- ----------
WLAN_FUTURE_EVENT                                                                                        TABLE
EMPLOYEES                                                                                                        TABLE
EMP_SAL2                                                                                                         VIEW
P1                                                                                                                     TABLE
P2                                                                                                                     TABLE
P3                                                                                                                     TABLE

6 rows selected.

Elapsed: 00:00:00.02
SQL>
3)执行脚本"/","r",";"都可以,常用"/"
SQL> l
    1* select * from tab
SQL> r
    1* select * from tab

TNAME                                                                                                                TABTYPE                 CLUSTERID
------------------------------------------------------------ -------------- ----------
WLAN_FUTURE_EVENT                                                                                        TABLE
EMPLOYEES                                                                                                        TABLE
EMP_SAL2                                                                                                         VIEW
P1                                                                                                                     TABLE
P2                                                                                                                     TABLE
P3                                                                                                                     TABLE

6 rows selected.

Elapsed: 00:00:00.02
SQL> /

TNAME                                                                                                                TABTYPE                 CLUSTERID
------------------------------------------------------------ -------------- ----------
WLAN_FUTURE_EVENT                                                                                        TABLE
EMPLOYEES                                                                                                        TABLE
EMP_SAL2                                                                                                         VIEW
P1                                                                                                                     TABLE
P2                                                                                                                     TABLE
P3                                                                                                                     TABLE

6 rows selected.

Elapsed: 00:00:00.02
SQL> ;
    1* select * from tab
SQL>
4)多行切换及运用
1.查询缓存中的语句
SQL> l
    1    select tname
    2* from tab
SQL>
2.切换到第一行(*号表示当前行)
SQL> 1
    1* select tname
SQL>
3.删除行
SQL> del 2
SQL> l
    1* select tname
SQL>
4.增加行
SQL> i from tab    ----增加行
SQL> l
    1    select tname
    2* from tab
SQL>
5.修改内容
SQL> l
    1    select tname
    2* from tab
SQL> c \tab\your_table     ----修改tab为your_table
    2* from your_table
SQL> l
    1    select tname
    2* from your_table
SQL>
5)sqlplus配置vi为默认缓冲区编辑工具
1)进入sqlplus加目录
cd $ORACLE_HOME/sqlplus/admin/
2)编辑配置文件glogin.sql文件,在末尾加入
DEFINE_EDITOR=vi
3)在sqlplus环境中输入ed进入缓存编辑状态
SQL> l
    1    select tname
    2    from tab
    3* where tname in('p1','p2','p3','p4','p5')
SQL> ed                 ----和vi用法一样,:wq保存。
"afiedt.buf" 4 lines, 65 characters

    1    select tname
    2    from tab
    3* where tname in('P1','P2','P3','P4','P5')
SQL> l
    1    select tname
    2    from tab
    3* where tname in('P1','P2','P3','P4','P5')
SQL> /

TNAME
------------------------------------------------------------
P1
P2
P3

Elapsed: 00:00:00.01
SQL>


你可能感兴趣的:(sqlplus)