SQL> select * from v$version where rownum=1;

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

[oracle@localhost ~]$ cat /etc/issue

Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)

Kernel \r on an \m



sqlplus是经经常使用的工具了,它提供了非常多功能,用起来十分方便便捷。

1.获取帮助

SQL> help

 HELP

 ----

Accesses this command line help system. Enter HELP INDEX or ?

INDEX

 for a list of topics.





 You can view SQL*Plus resources at

     http://www.oracle.com/technology/tech/sql_plus/

 and the Oracle Database Library at

     http://www.oracle.com/technology/documentation/

 HELP|?

[topic]



SQL> help index

Enter Help [topic] for help.





 @             COPY         PAUSE                    SHUTDOWN

 @@            DEFINE       PRINT                    SPOOL

 /             DEL          PROMPT                   SQLPLUS

 ACCEPT        DESCRIBE     QUIT                     START

 APPEND        DISCONNECT   RECOVER                  STARTUP

 ARCHIVE LOG   EDIT         REMARK                   STORE

 ATTRIBUTE     EXECUTE      REPFOOTER                TIMING

 BREAK         EXIT         REPHEADER                TTITLE

 BTITLE        GET          RESERVED WORDS (SQL)     UNDEFINE

 CHANGE        HELP         RESERVED WORDS (PL/SQL)  VARIABLE

 CLEAR         HOST         RUN                      WHENEVER OSERROR

 COLUMN        INPUT        SAVE                     WHENEVER SQLERROR

 COMPUTE       LIST         SET                      XQUERY

 CONNECT       PASSWORD     SHOW

SQL> help set

 SET

 ---

Sets a system variable to alter the SQL*Plus environment settings

 for your current session. For example, to:

     -   set the display width for data

     -   customize HTML formatting

     -   enable or disable printing of column headings

     -   set the number of lines per page

 SET system_variable value

where system_variable and value represent one of the following clauses:

 APPI[NFO]{OFF|ON|text}                   NEWP[AGE] {1|n|NONE}

   ARRAY[SIZE] {15|n}                       NULL text

   AUTO[COMMIT] {OFF|ON|IMM[EDIATE]|n}      NUMF[ORMAT] format

   AUTOP[RINT] {OFF|ON}                     NUM[WIDTH] {10|n}

   AUTORECOVERY {OFF|ON}                    PAGES[IZE] {14|n}

   AUTOT[RACE] {OFF|ON|TRACE[ONLY]}         PAU[SE] {OFF|ON|text}

     [EXP[LAIN]] [STAT[ISTICS]]             RECSEP {WR[APPED]|EA[CH]|OFF}

   BLO[CKTERMINATOR] {.|c|ON|OFF}           RECSEPCHAR {_|c}

   CMDS[EP] {;|c|OFF|ON}                    SERVEROUT[PUT] {ON|OFF}

   COLSEP {_|text}                            [SIZE {n | UNLIMITED}]

   CON[CAT] {.|c|ON|OFF}                      [FOR[MAT]  {WRA[PPED] |

   COPYC[OMMIT] {0|n}                          WOR[D_WRAPPED] |

   COPYTYPECHECK {ON|OFF}                      TRU[NCATED]}]

   DEF[INE] {&|c|ON|OFF}                    SHIFT[INOUT] {VIS[IBLE] |

   DESCRIBE [DEPTH {1|n|ALL}]                 INV[ISIBLE]}

     [LINENUM {OFF|ON}] [INDENT {OFF|ON}]   SHOW[MODE] {OFF|ON}

   ECHO {OFF|ON}                            SQLBL[ANKLINES] {OFF|ON}

   EDITF[ILE] file_name[.ext]               SQLC[ASE] {MIX[ED] |

   EMB[EDDED] {OFF|ON}                        LO[WER] | UP[PER]}

   ERRORL[OGGING] {ON|OFF}                  SQLCO[NTINUE] {> | text}

     [TABLE [schema.]tablename]             SQLN[UMBER] {ON|OFF}

     [TRUNCATE] [IDENTIFIER identifier]     SQLPLUSCOMPAT[IBILITY] {x.y[.z]}

   ESC[APE] {\|c|OFF|ON}                    SQLPRE[FIX] {#|c}

   ESCCHAR {@|?

|%|$|OFF}                    SQLP[ROMPT] {SQL>|text}

   EXITC[OMMIT] {ON|OFF}                    SQLT[ERMINATOR] {;|c|ON|OFF}

   FEED[BACK] {6|n|ON|OFF}                  SUF[FIX] {SQL|text}

   FLAGGER {OFF|ENTRY|INTERMED[IATE]|FULL}  TAB {ON|OFF}

   FLU[SH] {ON|OFF}                         TERM[OUT] {ON|OFF}

   HEA[DING] {ON|OFF}                       TI[ME] {OFF|ON}

   HEADS[EP] {||c|ON|OFF}                   TIMI[NG] {OFF|ON}

   INSTANCE [instance_path|LOCAL]           TRIM[OUT] {ON|OFF}

   LIN[ESIZE] {80|n}                        TRIMS[POOL] {OFF|ON}

   LOBOF[FSET] {1|n}                        UND[ERLINE] {-|c|ON|OFF}

   LOGSOURCE [pathname]                     VER[IFY] {ON|OFF}

   LONG {80|n}                              WRA[P] {ON|OFF}

   LONGC[HUNKSIZE] {80|n}                   XQUERY {BASEURI text|

   MARK[UP] HTML [OFF|ON]                     ORDERING{UNORDERED|

     [HEAD text] [BODY text] [TABLE text]              ORDERED|DEFAULT}|

     [ENTMAP {ON|OFF}]                        NODE{BYVALUE|BYREFERENCE|

     [SPOOL {OFF|ON}]                              DEFAULT}|

     [PRE[FORMAT] {OFF|ON}]                   CONTEXT text}







2.查看表的结构:

SQL> desc v$process;

 名称                                    是否为空? 类型

 ----------------------------------------- -------- ----------------------------

 ADDR                                               RAW(4)

 PID                                                NUMBER

 SPID                                               VARCHAR2(24)

 PNAME                                              VARCHAR2(5)

 USERNAME                                           VARCHAR2(15)

 SERIAL#                                            NUMBER

 TERMINAL                                           VARCHAR2(30)

 PROGRAM                                            VARCHAR2(48)

 TRACEID                                            VARCHAR2(255)

 TRACEFILE                                          VARCHAR2(513)

 BACKGROUND                                         VARCHAR2(1)

 LATCHWAIT                                          VARCHAR2(8)

 LATCHSPIN                                          VARCHAR2(8)

 PGA_USED_MEM                                       NUMBER

 PGA_ALLOC_MEM                                      NUMBER

 PGA_FREEABLE_MEM                                   NUMBER

 PGA_MAX_MEM                                        NUMBER







3.编辑sql语句(以下罗列了一部分命令)

A[PPEND] text   将text附加到当前行之后

C[HANGE] /old/new 将当前行的old替换成old

CL[EAR]BUFF[ER]    清除缓冲区的全部行

DEL                       删除当前行

DEL x                     删除x行

L[IST]                    列出缓冲区的全部行

L[IST] x                 列出缓冲区的第x行

R[UN] 或者 /          执行缓冲区所保存的语句                

x                          将x行作为当前行



SQL> LIST

  1* select * from t

SQL> clear buffer;

buffer 已清除

SQL> list

SP2-0223: SQL 缓冲区中不存在行。


SQL> /

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

SQL> run

  1* select * from v$version

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production



4.保存,检索并执行文件

SAV[E] filename :将sqlplus里的缓冲区的内容保存到filename指定的文件里,append将缓冲区的内容追加到现有的文件之后。replace说明替换一个现有的文件

[{REPLACE|APPEND}]

GET filename:将filename里指定的内容读入到sqlplus缓冲区中

STA[RT] filename:将filename里指定的内容读入到sqlplus缓冲区中,并执行

@filename:同start命令

ED[IT]:sqlplus里缓冲区的内容拷贝到一个命为afiedt.buf的文件里,然后启动os默认的编辑器。在退出编辑器时。当中的内容被拷贝到sqlplus缓冲区中

ED[IT] filename:与edit同样。不同的是指定了文件名称

SPO[OL] filename:sqlplus缓冲区的内容拷贝到filename文件里

SPO[OL] OFF:停止sqlplus的输出结果拷贝到filename指定的文件里。并关闭该文件





SQL> edit

已写入 file afiedt.buf

  1* select * from v$version

SQL> !cat afiedt.buf

select * from v$version

/


SPOOL用的次数非常多,非常方便查看

SQL> spool diy_os.lst 

SQL> select * from v$version;

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

PL/SQL Release 11.2.0.1.0 - Production

CORE    11.2.0.1.0      Production

TNS for Linux: Version 11.2.0.1.0 - Production

NLSRTL Version 11.2.0.1.0 - Production

SQL> spool off;

SQL> !cat wang.lst

SQL> select * from v$version;

BANNER                                                                          

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production          

PL/SQL Release 11.2.0.1.0 - Production                                          

CORE    11.2.0.1.0      Production                                                      

TNS for Linux: Version 11.2.0.1.0 - Production                                  

NLSRTL Version 11.2.0.1.0 - Production                                          

SQL> spool off;





5.格式化列。清除列格式

COL[UMN] {column | alias}[options]

column指定列名

alias 指定格式化列的别名

option 指定用于格式化列或者别名的一个或多个选项

格式化选项:

FOR[MATE] format:将列或别名的显示格式设置为由format字符串指定的格式

HEA[DING] heading:将列或别名的标题中的文本设置成有heading字符串指定的格式

JUS[TIFY]  [{LEFT|CENTER|RIGHT}] :将列输出设置为左对齐,居中,或右对齐

WRA[PPED]:在输出结果中将一个字符串的末尾换行显示,该选项可能导致单个单词跨越多行

WOR[D_WRAPPED]:与WRAPPED选项类似,不同之处在于单个单词不会跨越两行

CLE[AR]:清除列的不论什么格式化(将格式设置成默认)=>colum id clear;

  上面format能够使用非常多格式化參数

 比方:    

COLUMN LAST_NAME FORMAT A20 HEADING 'EMPLOYEE|NAME'

COLUMN SALARY FORMAT $9,999,990.99

COLUMN SALARY+COMMISSION_PCT+BONUS-EXPENSES-INS-TAX ALIAS NET

COLUMN NET FORMAT $9,999,999.99 NULL '<NULL>'

COLUMN REMARKS FORMAT A20 WRAP

下面摘自官方文档:  http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve013.htm

Character Columns 

The default width of CHAR, NCHAR, VARCHAR2
(VARCHAR) and NVARCHAR2 (NCHAR VARYING) columns is the width of the column in the database. SQL*Plus formats these datatypes left-justified. If a
value does not fit within the column width, SQL*Plus wraps or truncates the character string depending on the setting of SET WRAP.

A LONG, BLOB, BFILE, CLOB,
NCLOB or XMLType column's width defaults to the value of SET LONGCHUNKSIZE
or SET LONG, whichever one is smaller.

SQL*Plus truncates or wraps XMLType columns after 2000 bytes. To avoid this you need to set an explicit COLUMN format for the XMLType column. A COLUMN format can be up to a maximum of 60000 per row.

To change the width of a datatype
to n, use FORMAT An. (A stands for alphabetic.) If you specify a width shorter than the column heading,
SQL*Plus truncates the heading.

DATE Columns 

The default width and format of unformatted DATE columns in SQL*Plus is derived from the NLS_DATE_FORMAT parameter. The NLS_DATE_FORMAT setting is determined by the NLS territory parameter. For example, the default format for the NLS territory, America, is
DD-Mon-RR, and the default width is A9. The NLS parameters may be set in your database parameter file, in environment variables or an equivalent platform-specific mechanism. They may also be specified for each session with the ALTER SESSION command. For more
information about DATE formats, and about NLS parameters, see the Oracle
Database SQL Language Reference
.

You can change the format of any DATE column using the SQL function TO_CHAR in your SQL SELECT statement. You may also wish to use an explicit COLUMN
FORMAT command to adjust the column width.

When you use SQL functions like TO_CHAR, Oracle Database automatically enables a very wide column. The default column width may also depend on the character sets in use in SQL*Plus and in the database. To maximize script portability if multiple characters sets
are used, Oracle Database recommends using COLUMN FORMAT for each column selected.

To change the width of a DATE column to n, use the COLUMN command with FORMAT An. If you specify a width
shorter than the column heading, the heading is truncated.

NUMBER Columns For numeric columns, COLUMN FORMAT settings take precedence over SET NUMFORMAT settings, which take precedence over SET NUMWIDTH settings.

See SET NUMF[ORMAT] format and SET
NUM[WIDTH] {10 | n}
.

To change a NUMBER column's width,
use FORMAT followed by an element as specified in Table
12-1, "Number Formats"
.

Table 12-1 Number Formats

Element Examples Description

, (comma)

9,999

Displays a comma in the specified position.

. (period)

99.99

Displays a period (decimal point) to separate the integral and fractional parts of a number.

$

$9999

Displays a leading dollar sign.

0

0999 9990

Displays leading zeros Displays trailing zeros.

9

9999

Displays a value with the number of digits specified by the number of 9s. Value has a leading space if positive, a leading minus sign if negative. Blanks are displayed for leading zeroes. A zero (0) is displayed for a value of zero.

B

B9999

Displays blanks for the integer part of a fixed-point number when the integer part is zero, regardless of zeros in the format model.

C

C999

Displays the ISO currency symbol in the specified position.

D

99D99

Displays the decimal character to separate the integral and fractional parts of a number.

EEEE

9.999EEEE

Displays value in scientific notation (format must contain exactly four "E"s).

G

9G999

Displays the group separator in the specified positions in the integral part of a number.

L

L999

Displays the local currency symbol in the specified position.

MI

9999MI

Displays a trailing minus sign after a negative value. Display a trailing space after a positive value.

PR

9999PR

Displays a negative value in <angle brackets>. Displays a positive value with a leading and trailing space.

RN rn

RN rn

Displays uppercase Roman numerals. Displays lowercase Roman numerals. Value can be an integer between 1 and 3999.

S

S9999 9999S

Displays a leading minus or plus sign. Displays a trailing minus or plus sign.

TM

TM

Displays the smallest number of decimal characters possible. The default is TM9. Fixed notation is used for output up to 64 characters, scientific notation for more than 64 characters. Cannot precede TM with any other element. TM can only be followed by a single
9 or E

U

U9999

Displays the dual currency symbol in the specified position.

V

999V99

Displays value multiplied by 10n, where n is the number of 9's after the V.

X

XXXX xxxx

Displays the hexadecimal value for the rounded value of the specified number of digits.


]6.设置页面。行大小

SQL> set pagesize 100

SQL> set linesize 100

SQL> select * from dba_data_files where rownum<4;

FILE_NAME

----------------------------------------------------------------------------------------------------

   FILE_ID TABLESPACE_NAME                     BYTES     BLOCKS STATUS    RELATIVE_FNO AUT

---------- ------------------------------ ---------- ---------- --------- ------------ ---

  MAXBYTES  MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS ONLINE_

---------- ---------- ------------ ---------- ----------- -------

/u01/app/oracle/oradata/orcl3939/user01.dbf

         4 USERS                            52428800       6400 AVAILABLE           4 NO

         0          0            0   51380224        6272 ONLINE

/u01/app/oracle/oradata/orcl3939/undotbs01.dbf

         3 UNDOTBS1                        917504000     112000 AVAILABLE           3 YES

3.4360E+10    4194302          640  916455424      111872 ONLINE

/u01/app/oracle/oradata/orcl3939/sysaux01.dbf

         2 SYSAUX                          754974720      92160 AVAILABLE           2 YES

3.4360E+10    4194302         1280  753926144       92032 ONLINE

版权声明:本文博主原创文章,博客,未经同意,不得转载。

左右sqlplus一些方法用于汇总的更多相关文章

  1. sqlplus 配置方法及相关命令

    sqlplus 配置方法及相关命令 1.配置文件 1.1 全局模式什么叫全局模式呢:当我们配置完sqlplus工具加载配置文件后,无论在哪个目录下登陆数据库,您设置[sqlplus提示符样子,在任何目 ...

  2. C++常用字符串分割方法实例汇总

    投稿:shichen2014 字体:[增加 减小] 类型:转载 时间:2014-10-08我要评论 这篇文章主要介绍了C++常用字符串分割方法实例汇总,包括了strtok函数.STL.Boost等常用 ...

  3. HTML5 Audio/Video 标签,属性,方法,事件汇总

    HTML5 Audio/Video 标签,属性,方法,事件汇总 (转) 2011-06-28 13:16:48   <audio> 标签属性:src:音乐的URLpreload:预加载au ...

  4. [ jquery 过滤器 hasClass(class) ] 此方法用于在选择器的基础之上检查当前的元素是否含有某个特定的类,如果有,则返回true

    此方法用于在选择器的基础之上检查当前的元素是否含有某个特定的类,如果有,则返回true 实例: <!DOCTYPE html> <html lang='zh-cn'> < ...

  5. Exporter - 实现默认的导入方法用于模块

    Exporter - 实现默认的导入方法用于模块 简介: In module YourModule.pm: package YourModule; require Exporter; @ISA = q ...

  6. setTimeout 方法用于在指定的毫秒数后调用函数或计算表达式

    setTimeout 方法用于在指定的毫秒数后调用函数或计算表达式

  7. AsyncTask onPreExecute方法用于在执行后台任务前做一些UI操作

    1.实例化 TableListsTask task = new TableListsTask(ServerIP,"ALL", MenuActivity.this);   //第三参 ...

  8. 自己封装的一个js方法用于获取显示的星期和日期时间

    自己封装的一个js方法用于获取显示的星期和日期时间 /** * 获取用于显示的星期和日期时间 * @param date * @returns {string} */ function getWeek ...

  9. Fundebug前端JavaScript插件更新至1.6.0,新增test()方法用于测试

    摘要: 1.6.0新增fundebug.test()方法用于测试,请大家及时更新. 默认情况下,Fundebug 插件能够自动捕获未处理的错误(uncaught error).另外,开发者也可以通过使 ...

随机推荐

  1. tab功能菜单——使用tab之间不同的交换机div

    需求:在web实现类型的接口tab标签效应 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvem91eXVqaWUxMTI3/font/5a6L5L2T/fo ...

  2. hdu5115(区间dp)

    n头狼排成一列,每头狼有两个属性,基础攻击力和附加攻击力, 第i只狼的基础攻击力是ai,附加攻击力是b(i-1) + b(i+1) 消灭一只狼,受到的伤害为基础攻击力+附加攻击力. 问消灭所有的狼受到 ...

  3. Android开发工具综述,开发人员必备工具

    安卓开发工具汇总.开发者必备.安卓开发过程中须要用到各种工具,作为一名安卓开发者,有木有感到亚历山大,那么多工具! 今天给大家汇总了一下安卓开发工具,安卓开发者必备利器. 1.Draw 9-Patch ...

  4. java + memcached安装

    一:安装 (临时获取上手windows实验) 1.下载memcached.exe , 上F:\memcached\ 下 2.在CMD在输入 "F:\memcached\memcached.e ...

  5. Codeforces Round#297 div2

    B: 题意:给定一个字符串,然后给定m个数字 对于每个数字ai的含义是,将ai到n-ai+1的字符串给翻转一遍. 要求输出m次翻转之后的字符串. 想法就是判断第i个位置的字符是翻转了奇数次,还是偶数次 ...

  6. Windows Phone开发(5):室内装修

    原文:Windows Phone开发(5):室内装修 为什么叫室内装修呢?呵呵,其实说的是布局,具体些嘛,就是在一个页面中,你如何去摆放你的控件,如何管理它们,你说,像不像我们刚搬进新住所,要&quo ...

  7. windows phone (22) 隐藏元素

    原文:windows phone (22) 隐藏元素 在wp中我们也会用到隐藏某个元素,已达到某种效果,刚刚从文章看到了,分享一下[作者:神舟龙] Visibility 此属性能非常方便的实现隐藏某个 ...

  8. htc one x刷机记录

    这几天有些空余时间都用来刷htc one x,来说说刷机的艰难史吧. 首先是利用百度云rom刷机,本来一直用小米系统,突然发现百度云也能够搞个,所以心血来潮要刷个百度云,先利用软件解锁,哪知道没细致看 ...

  9. ASP.NET中的ExecuteNonQuery()方法的用法

    下面我将详细讲解在机房收费系统D层中如何对数据库的增加.删除.修改,最后再来总结一下 ExecuteNonQuery(),ExecuteScalar(),ExecuteReader的用法: 一.增.删 ...

  10. hdu4771 Stealing Harry Potter&#39;s Precious

    注意--你可能会爆内存-- 假设一个直接爆搜索词-- 队列存储器元件被减少到-- #include<iostream> #include<map> #include<st ...