SQLPlus提供了很多常用的命令,以下是常用命令的使用方法及示例。
1-> SQLPlus的登陸與退出
sqlplus -H | -V -H 將顯示sqlplus的版本及幫助信息,-V將顯示其版本信息 登陸語法:is : ( [/ ][@ ] | /) [AS SYSDBA | AS SYSOPER] | /NOLOG [/ ]:登陸的用戶名,密碼 @ :數據庫的連接標識符,當未指定該參數,則連接到缺省的標識符 AS SYSDBA | AS SYSOPER:這兩個參數描述使用數據庫管理員的權限登陸 NOLOG:啟動未連接到數據庫的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來退出*/ 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來退出,如例子中所演示的
2->help? 獲得某一個命令的幫助信息
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](簡寫L)顯示緩沖區的所有內容。* 當前行,m 第m行,n 第n行,m 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->/ 執行緩沖區的內容
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 設置當前行
SQL
> 2
2*
where
sal > 2000
SQL
> 3
3*
and
deptno = 20
6->n text 用text內容替換第n行
7->;? 對于已輸入完畢的SQL語句,輸入;號表示該語句輸入完畢。對于設置語句可以不使用分號,如上述的help desc
?
8->APPEND text(簡寫A text) 將text的內容追加到緩沖區尾部
SQL
> l
1*
select
*
from
emp
SQL
> a
where
sal > 2000;
1*
select
*
from
empwhere sal > 2000
9->CHANGE/old/new(簡寫C /old/new) 將當前行中的old替換為new
10->CHANGE/text(C/text) 刪除當前行中的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)清除整個SQL緩沖區
12->DEL 刪除當前行
13->show user 顯示當前登陸的用戶
14->SAVE 保存當前緩沖區的內容到文件
15->GET 把磁盤上的命令文件調入到當前緩沖區
SQL
> cl buff
buffer cleared
SQL
>
get
query.
sql
1
select
*
2
from
emp
3*
where
sal > 2000
16->START/@ filename 運行命令文件
SQL
>
get
query.
sql
1
select
*
2
from
emp
3*
where
sal > 2000
SQL
> @query.
sql
17->SET LINESIZE n 設置每行的字符數,默認80,如果一行的輸出內容大于設置的一行可容納的字符數,則折行顯示。
SQL > select * from scott.emp where ename = ' SCOTT '; /*以下是未設置的結果*/ 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 '; /*以下是設置后的結果*/ EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7788 SCOTT ANALYST 7566 19-APR-87 3000 20
18->dual 偽表的使用,注意Oracle與MSSQL的差異,下面的操作MSSQL無需偽表即可完成,幾不需要from dual就可以完成一些特定的功能
19->spool??? filename 將接下來屏幕上輸入的所有內容輸出到文件,包括輸入的SQL語句
20->spool off 需要使用off后,才能將內容輸出到文件
更多:
Linux (RHEL 5.4)下安裝Oracle 10g R2
使用Uniread實現SQLplus翻頁功能
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

