左右sqlplus一些方法用于汇总
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 |
|
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一些方法用于汇总的更多相关文章
- sqlplus 配置方法及相关命令
sqlplus 配置方法及相关命令 1.配置文件 1.1 全局模式什么叫全局模式呢:当我们配置完sqlplus工具加载配置文件后,无论在哪个目录下登陆数据库,您设置[sqlplus提示符样子,在任何目 ...
- C++常用字符串分割方法实例汇总
投稿:shichen2014 字体:[增加 减小] 类型:转载 时间:2014-10-08我要评论 这篇文章主要介绍了C++常用字符串分割方法实例汇总,包括了strtok函数.STL.Boost等常用 ...
- HTML5 Audio/Video 标签,属性,方法,事件汇总
HTML5 Audio/Video 标签,属性,方法,事件汇总 (转) 2011-06-28 13:16:48 <audio> 标签属性:src:音乐的URLpreload:预加载au ...
- [ jquery 过滤器 hasClass(class) ] 此方法用于在选择器的基础之上检查当前的元素是否含有某个特定的类,如果有,则返回true
此方法用于在选择器的基础之上检查当前的元素是否含有某个特定的类,如果有,则返回true 实例: <!DOCTYPE html> <html lang='zh-cn'> < ...
- Exporter - 实现默认的导入方法用于模块
Exporter - 实现默认的导入方法用于模块 简介: In module YourModule.pm: package YourModule; require Exporter; @ISA = q ...
- setTimeout 方法用于在指定的毫秒数后调用函数或计算表达式
setTimeout 方法用于在指定的毫秒数后调用函数或计算表达式
- AsyncTask onPreExecute方法用于在执行后台任务前做一些UI操作
1.实例化 TableListsTask task = new TableListsTask(ServerIP,"ALL", MenuActivity.this); //第三参 ...
- 自己封装的一个js方法用于获取显示的星期和日期时间
自己封装的一个js方法用于获取显示的星期和日期时间 /** * 获取用于显示的星期和日期时间 * @param date * @returns {string} */ function getWeek ...
- Fundebug前端JavaScript插件更新至1.6.0,新增test()方法用于测试
摘要: 1.6.0新增fundebug.test()方法用于测试,请大家及时更新. 默认情况下,Fundebug 插件能够自动捕获未处理的错误(uncaught error).另外,开发者也可以通过使 ...
随机推荐
- Yii学习笔记之三(在windows 上安装 advanced )
首先说一下下载地址: http://www.yiiframework.com/download/ 然后将下载下来的文件进行解压到 你指定的文件夹 解压过程中假设报什么错误 直接忽略掉 我的解压文件夹是 ...
- css实现背景渐变色效果
webkit内核的浏览器,例如(chrome,safari等) background:-webkit-gradient(linear,0 0,0 100%,from(#000000),to(#ffff ...
- C陷阱与缺陷之语法陷阱
2.1理解函数声明 不论什么C变量的声明都由两部分组成:类型以及一组类似表达式的声明符号.比如 float f; 这个声明的含义是:当对其求值时,表达式f和g的类型为浮点数类.由于声 明符与表达式的相 ...
- 何谓集群(cluster)
1.簇 1.1 何谓集群 简单的说.簇(cluster)是一组计算机.他们,作为一个一般的为客户提供了一套网络资源.该计算机系统是集群中的单个节点(node). 个理想的集群是,用户从来不会意识到集群 ...
- Robotium原则的实施源代码分析
从前面的章节<Robotium源代码分析之Instrumentation进阶>中我们了解到了Robotium所基于的Instrumentation的一些进阶基础.比方它注入事件的原理等,但 ...
- 【原创】poj ----- 1182 食物链 解题报告
题目地址: http://poj.org/problem?id=1182 题目内容: 食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- 足球和oracle列(4):巴西惨败于德国,认为,差额RAC拓扑控制!
足球与oracle系列(4):从巴西慘败于德国,想到,差异的RAC拓扑对照! 前期回想: 本来想说今晚,回头一想,应该是今早第二场半决赛就要开战了!先来回味一下之前的比赛,本届8支小组赛第一名已经所有 ...
- Word001
C# Word 类库 2009-08-06 22:10 13470人阅读 评论(10) 收藏 举报 c#objectstring文档microsoftexcel using System;using ...
- Type mismatch: cannot convert from Enumeration<String> to Enumeration<Object>
完整的错误信息: Description Resource Path Location TypeType mismatch: cannot convert from Enumeration<St ...
- 冒泡排序算法(Java)
冒泡排序即每次遍历.相邻数字间进行比較,前者大于后者进行交换,不断将最大值后移,直至沉至最后位置:算法关键要点在于确定每次循环的边界. 后面两种算法则是对冒泡排序一定程度上的改良,但相对于其它排 ...