SQLPlus提供了很多常用的命令,以下是常用命令的使用方法及示例。
1-> SQLPlus的登陸與退出
sqlplus -H | -V -H 將顯示sqlplus的版本及幫助信息,-V將顯示其版本信息 登陸語(yǔ)法:is : ( [/ ][@ ] | /) [AS SYSDBA | AS SYSOPER] | /NOLOG [/ ]:登陸的用戶名,密碼 @ :數(shù)據(jù)庫(kù)的連接標(biāo)識(shí)符,當(dāng)未指定該參數(shù),則連接到缺省的標(biāo)識(shí)符 AS SYSDBA | AS SYSOPER:這兩個(gè)參數(shù)描述使用數(shù)據(jù)庫(kù)管理員的權(quán)限登陸 NOLOG:?jiǎn)?dòng)未連接到數(shù)據(jù)庫(kù)的SQLPlus,在這之后可以使用conn登陸 下面是三種不同的登陸方式 [oracle@linux ~]$ sqlplus scott/tigger SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 30 14:04:06 2010 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 [oracle@linux ~]$ sqlplus /nolog SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 30 14:04:45 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. SQL> conn scott Enter password: Connected. SQL> exit /*使用exit或quit來(lái)退出*/ SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options [oracle@linux ~]$ sqlplus " /as sysdba " SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 30 14:05:44 2010 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 退出:使用使用exit或quit來(lái)退出,如例子中所演示的
2->help? 獲得某一個(gè)命令的幫助信息
SQL > help desc DESCRIBE -------- Lists the column definitions for a table , view , or synonym, or the specifications for a function or procedure . DESC [RIBE] {[ schema .]object[@connect_identifier]
3->LIST [m][*] [n](簡(jiǎn)寫L)顯示緩沖區(qū)的所有內(nèi)容。* 當(dāng)前行,m 第m行,n 第n行,m n 同時(shí)出現(xiàn),m到n行
SQL > l 1 select * from emp 2 where sal > 2000 3* and deptno = 20 SQL > l 2 3 2 where sal > 2000 3* and deptno = 20
4->/ 執(zhí)行緩沖區(qū)的內(nèi)容
SQL > l 1 select * from emp 2 where sal > 2000 3 and deptno = 20 4* and ename = ' SCOTT ' SQL > / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7788 SCOTT ANALYST 7566 19-APR-87 3000 20
5->n 設(shè)置當(dāng)前行
SQL > 2 2* where sal > 2000 SQL > 3 3* and deptno = 20
6->n text 用text內(nèi)容替換第n行
8->APPEND text(簡(jiǎn)寫A text) 將text的內(nèi)容追加到緩沖區(qū)尾部
SQL > l 1* select * from emp SQL > a where sal > 2000; 1* select * from empwhere sal > 2000
9->CHANGE/old/new(簡(jiǎn)寫C /old/new) 將當(dāng)前行中的old替換為new
10->CHANGE/text(C/text) 刪除當(dāng)前行中的text
SQL > l 1 select * from emp 2 where sal > 2000 3* and deptno = 10 SQL > 3 3* and deptno = 10 SQL > c / and deptno = 10 3* SQL > l 1 select * from emp 2 where sal > 2000 3*
11->CLEAR BUFFER(CL BUFF)清除整個(gè)SQL緩沖區(qū)
14->SAVE 保存當(dāng)前緩沖區(qū)的內(nèi)容到文件
15->GET 把磁盤上的命令文件調(diào)入到當(dāng)前緩沖區(qū)
SQL > cl buff buffer cleared SQL > get query. sql 1 select * 2 from emp 3* where sal > 2000
16->START/@ filename 運(yùn)行命令文件
SQL > get query. sql 1 select * 2 from emp 3* where sal > 2000 SQL > @query. sql
17->SET LINESIZE n 設(shè)置每行的字符數(shù),默認(rèn)80,如果一行的輸出內(nèi)容大于設(shè)置的一行可容納的字符數(shù),則折行顯示。
SQL > select * from scott.emp where ename = ' SCOTT '; /*以下是未設(shè)置的結(jié)果*/ EMPNO ENAME JOB MGR HIREDATE SAL COMM ---------- ---------- --------- ---------- --------- ---------- ---------- DEPTNO ---------- 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 SQL > set linesize 200 SQL > select * from scott.emp where ename = ' SCOTT '; /*以下是設(shè)置后的結(jié)果*/ EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7788 SCOTT ANALYST 7566 19-APR-87 3000 20
19->spool??? filename 將接下來(lái)屏幕上輸入的所有內(nèi)容輸出到文件,包括輸入的SQL語(yǔ)句
20->spool off 需要使用off后,才能將內(nèi)容輸出到文件
更多: Linux (RHEL 5.4)下安裝Oracle 10g R2 使用Uniread實(shí)現(xiàn)SQLplus翻頁(yè)功能
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
