国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

Oracle的sql*plus

2024-08-29 13:29:37
字體:
來源:轉載
供稿:網友
oracle的sql*plus是與oracle進行交互的客戶端工具。在sql*plus中,可以運行sql*plus命令與sql*plus語句。
   我們通常所說的dml、ddl、dcl語句都是sql*plus語句,它們執行完后,都可以保存在一個被稱為sql buffer的內存區域中,并且只能保存一條最近執行的sql語句,我們可以對保存在sql buffer中的sql 語句進行修改,然后再次執行,sql*plus一般都與數據庫打交道。
   除了sql*plus語句,在sql*plus中執行的其它語句我們稱之為sql*plus命令。它們執行完后,不保存在sql buffer的內存區域中,它們一般用來對輸出的結果進行格式化顯示,以便于制作報表。
   下面就介紹一下一些常用的sql*plus命令:
 
1. 執行一個sql腳本文件
sql>start file_name
sql>@ file_name
我們可以將多條sql語句保存在一個文本文件中,這樣當要執行這個文件中的所有的sql語句時,用上面的任一命令即可,這類似于dos中的批處理。
 
2. 對當前的輸入進行編輯
sql>edit
 
3. 重新運行上一次運行的sql語句
sql>/
 
4. 將顯示的內容輸出到指定文件
sql> spool file_name
   在屏幕上的所有內容都包含在該文件中,包括你輸入的sql語句。
 
5. 關閉spool輸出
sql> spool off
   只有關閉spool輸出,才會在輸出文件中看到輸出的內容。
 
6.顯示一個表的結構
sql> desc table_name
 
7. col命令:
主要格式化列的顯示形式。
該命令有許多選項,具體如下:
col[umn] [{ column|expr} [ option ...]]
option選項可以是如下的子句:
ali[as] alias
cle[ar]
fold_a[fter]
fold_b[efore]
for[mat] format
hea[ding] text
jus[tify] {l[eft]|c[enter]|c[entre]|r[ight]}
like { expr|alias}
newl[ine]
new_v[alue] variable
nopri[nt]|pri[nt]
nul[l] text
old_v[alue] variable
on|off
wra[pped]|wor[d_wrapped]|tru[ncated]
 
1). 改變缺省的列標題
column column_name heading column_heading
for example:
sql>select * from dept;
     deptno dname                        loc
---------- ---------------------------- ---------
         10 accounting                   new york
sql>col  loc heading location
sql>select * from dept;
    deptno dname                        location
--------- ---------------------------- -----------
        10 accounting                   new york
 
2). 將列名ename改為新列名employee name并將新列名放在兩行上:
sql>select * from emp
department  name           salary
---------- ---------- ----------
         10 aaa                11        
sql> column ename heading ’employee|name’
sql>select * from emp
            employee
department  name           salary
---------- ---------- ---------- 
         10 aaa                11
note: the col heading turn into two lines from one line.
 
3). 改變列的顯示長度:
for[mat] format
sql>select empno,ename,job from emp;
      empno ename      job       
---------- ----------     ---------
       7369 smith      clerk     
       7499 allen      salesman  
7521 ward       salesman  
sql> col ename format a40
      empno ename                                    job
----------   ----------------------------------------         ---------
       7369 smith                                    clerk
       7499 allen                                    salesman
       7521 ward                                    salesman
 
4). 設置列標題的對齊方式
jus[tify] {l[eft]|c[enter]|c[entre]|r[ight]}
sql> col ename justify center
sql> /
      empno           ename                   job
----------   ----------------------------------------       ---------
       7369 smith                                    clerk
       7499 allen                                    salesman
7521 ward                                     salesman
對于number型的列,列標題缺省在右邊,其它類型的列標題缺省在左邊
 
5). 不讓一個列顯示在屏幕上
nopri[nt]|pri[nt]
sql> col job noprint
sql> /
      empno           ename
----------     ----------------------------------------
       7369 smith
       7499 allen
7521 ward
 
6). 格式化number類型列的顯示:
sql> column sal format $99,990
sql> /
employee
department name        salary    commission
---------- ---------- --------- ----------
30          allen        $1,600    300
 
7). 顯示列值時,如果列值為null值,用text值代替null值
comm nul[l] text
sql>col comm nul[l] text
 
8). 設置一個列的回繞方式
wra[pped]|wor[d_wrapped]|tru[ncated]
        col1
--------------------
how are you?
 
sql>col col1 format a5
sql>col col1 wrapped
col1
-----
how a
re yo
u?
 
sql> col col1 word_wrapped
col1
-----
how
are
you?
 
sql> col col1 word_wrapped
col1
-----
how a
 
9). 顯示列的當前的顯示屬性值
sql> column column_name
 
10). 將所有列的顯示屬性設為缺省值
sql> clear columns
 
8. 屏蔽掉一個列中顯示的相同的值
break on break_column
sql> break on deptno
sql> select deptno, ename, sal
from emp
  where sal < 2500
  order by deptno;
deptno      ename         sal
---------- ----------- ---------
10           clark        2450
miller      1300
20            smith       800
adams       1100
 
9. 在上面屏蔽掉一個列中顯示的相同的值的顯示中,每當列值變化時在值變化之前插入n個空行。
break on break_column skip n
 
sql> break on deptno skip 1
sql> /
deptno ename sal
---------- ----------- ---------
10 clark 2450
miller 1300
 
20 smith 800
adams 1100
 
10. 顯示對break的設置
sql> break
 
11. 刪除6、7的設置
sql> clear breaks
 
12. set 命令:
該命令包含許多子命令:
set system_variable value
system_variable value 可以是如下的子句之一:
appi[nfo]{on|off|text}
array[size] {15|n}
auto[commit]{on|off|imm[ediate]|n}
autop[rint] {on|off}
autorecovery [on|off]
autot[race] {on|off|trace[only]} [exp[lain]] [stat[istics]]
blo[ckterminator] {.|c}
cmds[ep] {;|c|on|off}
colsep {_|text}
com[patibility]{v7|v8|native}
con[cat] {.|c|on|off}
copyc[ommit] {0|n}
copytypecheck {on|off}
def[ine] {&|c|on|off}
describe [depth {1|n|all}][linenum {on|off}][indent {on|off}]
echo {on|off}
editf[ile] file_name[.ext]
emb[edded] {on|off}
esc[ape] {/|c|on|off}
feed[back] {6|n|on|off}
flagger {off|entry |intermed[iate]|full}
flu[sh] {on|off}
hea[ding] {on|off}
heads[ep] {||c|on|off}
instance [instance_path|local]
lin[esize] {80|n}
lobof[fset] {n|1}
logsource [pathname]
long {80|n}
longc[hunksize] {80|n}
mark[up] html [on|off] [head text] [body text] [entmap {on|off}] [spool
{on|off}] [pre[format] {on|off}]
newp[age] {1|n|none}
null text
numf[ormat] format
num[width] {10|n}
pages[ize] {24|n}
pau[se] {on|off|text}
recsep {wr[apped]|ea[ch]|off}
recsepchar {_|c}
serverout[put] {on|off} [size n] [for[mat] {wra[pped]|wor[d_
wrapped]|tru[ncated]}]
shift[inout] {vis[ible]|inv[isible]}
show[mode] {on|off}
sqlbl[anklines] {on|off}
sqlc[ase] {mix[ed]|lo[wer]|up[per]}
sqlco[ntinue] {> |text}
sqln[umber] {on|off}
sqlpre[fix] {#|c}
sqlp[rompt] {sql>|text}
sqlt[erminator] {;|c|on|off}
suf[fix] {sql|text}
tab {on|off}
term[out] {on|off}
ti[me] {on|off}
timi[ng] {on|off}
trim[out] {on|off}
trims[pool] {on|off}
und[erline] {-|c|on|off}
ver[ify] {on|off}
wra[p] {on|off}
 
1). 設置當前session是否對修改的數據進行自動提交
sql>set auto[commit] {on|off|imm[ediate]| n}
 
2).在用start命令執行一個sql腳本時,是否顯示腳本中正在執行的sql語句
sql> set echo {on|off}
 
3).是否顯示當前sql語句查詢或修改的行數
sql> set feed[back] {6|n|on|off}
   默認只有結果大于6行時才顯示結果的行數。如果set feedback 1 ,則不管查詢到多少行都返回。當為off 時,一律不顯示查詢的行數
 
4).是否顯示列標題
sql> set hea[ding] {on|off}
當set heading off 時,在每頁的上面不顯示列標題,而是以空白行代替
 
5).設置一行可以容納的字符數
sql> set lin[esize] {80|n}
   如果一行的輸出內容大于設置的一行可容納的字符數,則折行顯示。
 
6).設置頁與頁之間的分隔
sql> set newp[age] {1|n|none}
當set newpage 0 時,會在每頁的開頭有一個小的黑方框。
當set newpage n 時,會在頁和頁之間隔著n個空行。
當set newpage none 時,會在頁和頁之間沒有任何間隔。
 
7).顯示時,用text值代替null值
sql> set null text
 
8).設置一頁有多少行數
sql> set pages[ize] {24|n}
如果設為0,則所有的輸出內容為一頁并且不顯示列標題
 
9).是否顯示用dbms_output.put_line包進行輸出的信息。
sql> set serverout[put] {on|off} 
在編寫存儲過程時,我們有時會用dbms_output.put_line將必要的信息輸出,以便對存儲過程進行調試,只有將serveroutput變量設為on后,信息才能顯示在屏幕上。
 
10).當sql語句的長度大于linesize時,是否在顯示時截取sql語句。
sql> set wra[p] {on|off}
   當輸出的行的長度大于設置的行的長度時(用set linesize n命令設置),當set wrap on時,輸出行的多于的字符會另起一行顯示,否則,會將輸出行的多于字符切除,不予顯示。
 
11).是否在屏幕上顯示輸出的內容,主要用與spool結合使用。
sql> set term[out] {on|off}
   在用spool命令將一個大表中的內容輸出到一個文件中時,將內容輸出在屏幕上會耗費大量的時間,設置set termspool off后,則輸出的內容只會保存在輸出文件中,不會顯示在屏幕上,極大的提高了spool的速度。
 
12).將spool輸出中每行后面多余的空格去掉
sql> set trims[out] {on|off} 
   
13)顯示每個sql語句花費的執行時間
set timing  {on|off}
 
14.修改sql buffer中的當前行中,第一個出現的字符串
c[hange] /old_value/new_value
sql> l
   1* select * from dept
sql> c/dept/emp
   1* select * from emp
 
15.編輯sql buffer中的sql語句
edi[t]
 
16.顯示sql buffer中的sql語句,list n顯示sql buffer中的第n行,并使第n行成為當前行
l[ist] [n]
 
17.在sql buffer的當前行下面加一行或多行
i[nput]
 
18.將指定的文本加到sql buffer的當前行后面
a[ppend]
sql> select deptno,
   2  dname
   3  from dept;
     deptno dname
---------- --------------
         10 accounting
         20 research
         30 sales
         40 operations
 
sql> l 2
   2* dname
sql> a ,loc
   2* dname,loc
sql> l
   1  select deptno,
   2  dname,loc
   3* from dept
sql> /
 
     deptno dname          loc
---------- -------------- -------------
         10 accounting     new york
         20 research       dallas
         30 sales          chicago
         40 operations     boston
 
19.將sql buffer中的sql語句保存到一個文件中
save file_name
 
20.將一個文件中的sql語句導入到sql buffer中
get file_name
 
21.再次執行剛才已經執行的sql語句
run
or
/
 
22.執行一個存儲過程
execute procedure_name
 
23.在sql*plus中連接到指定的數據庫
connect user_name/[email protected]_alias
 
24.設置每個報表的頂部標題
ttitle
 
25.設置每個報表的尾部標題
btitle
 
26.寫一個注釋
remark [text]
 
27.將指定的信息或一個空行輸出到屏幕上
prompt [text]
 
28.將執行的過程暫停,等待用戶響應后繼續執行
pause [text]
 
sql>pause adjust paper and press return to continue.
 
29.將一個數據庫中的一些數據拷貝到另外一個數據庫(如將一個表的數據拷貝到另一個數據庫)
copy {from database | to database | from database to database}
{append|create|insert|replace} destination_table
[(column, column, column, ...)] using query
 
sql>copy from scott/[email protected] to john/[email protected] 
create emp_temp
using select * from emp
 
30.不退出sql*plus,在sql*plus中執行一個操作系統命令:
host
 
sql> host hostname
該命令在windows下可能被支持。
 
31.在sql*plus中,切換到操作系統命令提示符下,運行操作系統命令后,可以再次切換回sql*plus:
!
 
sql>!
$hostname
$exit
sql>
 
該命令在windows下不被支持。
 
32.顯示sql*plus命令的幫助
help
如何安裝幫助文件:
sql>@ ? qlplus/admin/help/hlpbld.sql ? qlplus/admin/help/helpus.sql
sql>help index
 
33.顯示sql*plus系統變量的值或sql*plus環境變量的值
syntax
sho[w] option
where option represents one of the following terms or clauses:
system_variable
all
bti[tle]
err[ors] [{function|procedure|package|package body|
trigger|view|type|type body} [schema.]name]
lno
parameters [parameter_name]
pno
rel[ease]
repf[ooter]
reph[eader]
sga
spoo[l]
sqlcode
tti[tle]
user
 
1) . 顯示當前環境變量的值:
show all
 
2) . 顯示當前在創建函數、存儲過程、觸發器、包等對象的錯誤信息
show error
當創建一個函數、存儲過程等出錯時,變可以用該命令查看在那個地方出錯及相應的出錯信息,進行修改后再次進行編譯。
 
3) . 顯示初始化參數的值:
show parameters [parameter_name]
 
4) . 顯示數據庫的版本:
show rel[ease]
 
5) . 顯示sga的大小
show sga
 
6). 顯示當前的用戶名
show user

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 威信县| 云和县| 伊川县| 翁牛特旗| 贵州省| 蚌埠市| 阳江市| 武汉市| 平阳县| 太湖县| 安吉县| 巴林左旗| 新和县| 阿克| 昭平县| 临海市| 改则县| 庆安县| 香港 | 邓州市| 凯里市| 浑源县| 恩平市| 建湖县| 札达县| 唐河县| 临沧市| 亚东县| 新绛县| 上犹县| 两当县| 桦甸市| 仙游县| 崇义县| 讷河市| 长子县| 黄平县| 响水县| 广河县| 宁海县| 麦盖提县|