您好,登錄后才能下訂單哦!
sqlplus 命令學習
$ 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 一個允許你輸入sql語句地方 sql語句控制數據庫的存取
1 查出scott.emp表的編號,姓名
SQL> select empno , ename from scott.emp; 分號結束 回車執行
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
2 如何查看當前sql buffer 的語句
? 命令 -----> 看幫助
? 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的語句,比如加一個條件ename ='SCOTT';
SQL> ? EDIT
EDIT
----
Invokes 調用 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指定使用哪一個文本編輯器
windows用的記事本
怎么指定用那個編輯器-----》》》》??? 變量指定
方法1 :臨時指定
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 如何執行buffer cache 中的語句
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> / 執行sql buffer 中的sql語句
EMPNO ENAME
---------- ----------
7788 SCOTT
5 保存代碼一個腳本,下次執行
SQL> ? SAVE
SAVE
----
Saves the contents 內容 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
默認創建
替換
追加
注意:腳本一定存在有權限的目錄(oracle用戶有權限寫)
save /u01/app/oracle/1.sql
6 保存腳本后,我想到操作系統去看一下,然后再回來執行sqlplus命令 (不退出sqlplus 到系統上執行命令)
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 回車 ----》操作系統-----》exit -----》sqlplus
用法2: host 操作系統命令
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
復制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 所有系統都支持
在linux平臺下 可以用!替換host
7 退出sqlplus
exit
quit
8 在/u01/app/oracle 有一個sql腳本 在sqlplus 執行腳本???
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 會把屏幕上的輸出都保存到一個文件里-----》做日志用
? spool
用法;
spool 一個文件
執行命令
spool off 結束
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 連接數據庫
SQL> conn scott/oracle
Connected.
SQL> show user;
USER is "SCOTT"
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。