sqlplus 命令學(xué)習(xí)
成都創(chuàng)新互聯(lián)于2013年開始,先為赤坎等服務(wù)建站,赤坎等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為赤坎企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
$ sqlplus / as sysdba
SQL> help index 可以輸入sqlplus 命令
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
sqlplus 一個(gè)允許你輸入sql語(yǔ)句地方 sql語(yǔ)句控制數(shù)據(jù)庫(kù)的存取
1 查出scott.emp表的編號(hào),姓名
SQL> select empno , ename from scott.emp; 分號(hào)結(jié)束 回車執(zhí)行
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
2 如何查看當(dāng)前sql buffer 的語(yǔ)句
? 命令 -----> 看幫助
? list
SQL> ? list
LIST
----
Lists one or more lines of the most recently executed SQL command
or PL/SQL block which is stored in the SQL buffer. Enter LIST with
no clauses to list all lines. In SQL*Plus command-line you can also
use ";" to list all the lines in the SQL buffer. The buffer has no
command history list and does not record SQL*Plus commands.
L[IST] [n | n m | n * | n LAST | * | * n | * LAST | LAST]
輸入 l
3 我想修改一buffer的語(yǔ)句,比如加一個(gè)條件ename ='SCOTT';
SQL> ? EDIT
EDIT
----
Invokes 調(diào)用 an operating system text editor文本編輯器 on the contents of the
specified file or on the contents of the SQL buffer. The buffer
has no command history list and does not record SQL*Plus commands.
ED[IT] [file_name[.ext]]
SQL> ed
Wrote file afiedt.buf
38
?
?
q 退出
一定在linux指定使用哪一個(gè)文本編輯器
windows用的記事本
怎么指定用那個(gè)編輯器-----》》》》??? 變量指定
方法1 :臨時(shí)指定
define _editor=vi
輸入ed
方法2: 永久指定 把變量放在.bash_profile
[oracle@yutianedu ~]$ vim /home/oracle/.bash_profile
加入: export EDITOR=vi
[oracle@yutianedu ~]$ source /home/oracle/.bash_profile
[oracle@yutianedu ~]$ echo $EDITOR
vi
ed 修改
SQL> l 查看
1 select empno ,ename from scott.emp
2* where ename ='SCOTT'
4 如何執(zhí)行buffer cache 中的語(yǔ)句
SQL> ? /
/ (slash)
---------
Executes the most recently executed SQL command or PL/SQL block
which is stored in the SQL buffer. Use slash (/) at the command
prompt or line number prompt in SQL*Plus command line. The buffer
has no command history and does not record SQL*Plus commands.
SQL> l
1 select empno ,ename from scott.emp
2* where ename ='SCOTT'
SQL> / 執(zhí)行sql buffer 中的sql語(yǔ)句
EMPNO ENAME
---------- ----------
7788 SCOTT
5 保存代碼一個(gè)腳本,下次執(zhí)行
SQL> ? SAVE
SAVE
----
Saves the contents 內(nèi)容 of the SQL buffer in a script. The
buffer has no command history list and does not record SQL*Plus commands.
SAV[E] [FILE] file_name[.ext] [CRE[ATE] | REP[LACE] | APP[END]]
save 文件命令 create /replace /append
默認(rèn)創(chuàng)建
替換
追加
注意:腳本一定存在有權(quán)限的目錄(oracle用戶有權(quán)限寫)
save /u01/app/oracle/1.sql
6 保存腳本后,我想到操作系統(tǒng)去看一下,然后再回來執(zhí)行sqlplus命令 (不退出sqlplus 到系統(tǒng)上執(zhí)行命令)
SQL> ? HOST
HOST
----
Executes an operating system command without leaving SQL*Plus.
Enter HOST without command to display an operating system prompt.
You can then enter multiple operating system commands.
HO[ST] [command]
用法1 :host 回車 ----》操作系統(tǒng)-----》exit -----》sqlplus
用法2: host 操作系統(tǒng)命令
SQL> host ls -l /u01/app/oracle
total 24
-rw-r--r-- 1 oracle oinstall 58 Oct 11 15:26 1.sql
drwxr-x--- 3 oracle oinstall 4096 Oct 11 14:10 admin
清屏clear ---->host clear
復(fù)制1.sql到/tmp目錄
SQL> host cp /u01/app/oracle/1.sql /tmp
SQL> host ls -l /tmp
total 524
-rw-r--r-- 1 oracle oinstall 58 Oct 11 15:30 1.sql
刪除 /tmp下的1.sql
host rm /tmp/1.sql
host 所有系統(tǒng)都支持
在linux平臺(tái)下 可以用!替換host
7 退出sqlplus
exit
quit
8 在/u01/app/oracle 有一個(gè)sql腳本 在sqlplus 執(zhí)行腳本???
SQL> ? @
@ ("at" sign)
-------------
Runs the SQL*Plus statements in the specified script. The script can be
called from the local file system or a web server.
或者用
SQL> ? start
START
-----
Runs the SQL*Plus statements in the specified script. The script can be
called from the local file system or a web server.
STA[RT] {url|file_name[.ext]} [arg ...]
@/u01/app/oracle/1.sql
start /u01/app/oracle/1.sql
9 會(huì)把屏幕上的輸出都保存到一個(gè)文件里-----》做日志用
? spool
用法;
spool 一個(gè)文件
執(zhí)行命令
spool off 結(jié)束
10 如何在用戶之間切換
conn 賬戶名/密碼
SQL> show user;
USER is "SYS"
SQL> conn scott/oracle
sConnected.
SQL>show user;
USER is "SCOTT"
SQL> conn hr/hr
Connected.
SQL> conn / as sysdba
Connected.
SQL> show user;
USER is "SYS"
sqlplus /nolog 登錄需要connect 連接數(shù)據(jù)庫(kù)
SQL> conn scott/oracle
Connected.
SQL> show user;
USER is "SCOTT"