1、單獨(dú)備份一個(gè)或多個(gè)用戶:
D:>exp scott/tiger file=導(dǎo)出文件
D:>exp system/manager owner=(用戶1,用戶2,…,用戶n) file=導(dǎo)出文件
2、單獨(dú)備份一個(gè)或多個(gè)表:
D:>exp 用戶/密碼 tables=表
D:>exp 用戶/密碼 tables=(表1,…,表2)
D:>exp system/manager tables=(用戶.表)
D:>exp system/manager tables=(用戶1.表1,用戶2.表2)
3、導(dǎo)入指定表
D:>exp scott/tiger file=a.dmp
D:>imp test/test fromuser=scott tables=emp file=a.dmp
D:>imp test/test tables=dept file=a.dmp
(說明:如果導(dǎo)出用戶沒有DBA權(quán)限,則導(dǎo)入用戶可以不用指定fromuser、touser參數(shù)如果導(dǎo)出用戶擁有DBA權(quán)限,則導(dǎo)入用戶也必須擁有DBA權(quán)限)
4、給表、列加注釋
SQL>comment on table 表 is '表注釋';
注釋已創(chuàng)建。
SQL>comment on column 表.列 is '列注釋';
注釋已創(chuàng)建。
SQL> select * from user_tab_comments where comments is not null;
SQL> select * from user_col_comments where comments is not null;
5、查看當(dāng)前用戶下有什么對(duì)象(表、視圖、同義詞、快照)
SQL> select * from tab;
查看表結(jié)構(gòu)
SQL> describe 表名
簡寫以上命令
SQL> desc 表名
6、
DDL、數(shù)據(jù)定義語言:create、alter、drop、truncate(創(chuàng)建、修改結(jié)構(gòu)、刪除、截?cái)啵ㄆ渌簉ename)
DML、數(shù)據(jù)操縱語言:insert、delete、select、update(增、刪、查、改)
DCL、數(shù)據(jù)控制語言:grant、revoke(授權(quán)、回收)、set role
事務(wù)控制:commit、rollback、savepoint(其他:lock table、set constraint(s)、set transaction)
審計(jì)控制:audit、noaudit
系統(tǒng)控制:alter system
會(huì)話控制:alter session
其他語句:comment(添加注釋)、explain plan、analyze(收集統(tǒng)計(jì))、validate、call
7、
1)、查看當(dāng)前所有對(duì)象
SQL> select * from tab;
2)、建一個(gè)和a表結(jié)構(gòu)一樣的空表
SQL> create table b as select * from a where 1=2;
SQL> create table b(b1,b2,b3) as select a1,a2,a3 from a where 1=2;
3)、察看數(shù)據(jù)庫的大小,和空間使用情況
SQL> col tablespace format a20
SQL> select b.file_id 文件ID,
b.tablespace_name 表空間,
b.file_name 物理文件名,
b.bytes 總字節(jié)數(shù),
(b.bytes-sum(nvl(a.bytes,0))) 已使用,
sum(nvl(a.bytes,0)) 剩余,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩余百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
/
dba_free_space --表空間剩余空間狀況
dba_data_files --數(shù)據(jù)文件空間占用情況
4)、查看現(xiàn)有回滾段及其狀態(tài)
SQL> col segment format a30
SQL> SELECT SEGMENT_NAME,OWNER,TABLESPACE_NAME,SEGMENT_ID,FILE_ID,STATUS FROM DBA_ROLLBACK_SEGS;
5)、查看數(shù)據(jù)文件放置的路徑
SQL> col file_name format a50
SQL> select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files order by file_id;
6)、顯示當(dāng)前連接用戶
SQL> show user
7)、把SQL*Plus當(dāng)計(jì)算器
SQL> select 100*20 from dual;
8)、連接字符串
SQL> select 列1||列2 from 表1;
SQL> select concat(列1,列2) from 表1;
9)、查詢當(dāng)前日期
SQL> select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss') from dual;
10)、用戶間復(fù)制數(shù)據(jù)
SQL> copy from user1 to user2 create table2 using select * from table1;
11)、視圖中不能使用order by,但可用group by代替來達(dá)到排序目的
SQL> create view a as select b1,b2 from b group by b1,b2;
12)、通過授權(quán)的方式來創(chuàng)建用戶
SQL> grant connect,resource to test identified by test;
13)、備份
create table yhda_bak as select * from yhda;
14)、提出相同的記錄
select sid,count(*) from yhda a group by sid having count(*)>1
15)、select的函數(shù)
ORDER BY – 按照指定列排序返回結(jié)果的子句
DISTINCT – 只返回結(jié)果集合內(nèi)唯一行的關(guān)鍵詞
COUNT -- 返回匹配查詢的數(shù)據(jù)行總數(shù)數(shù)值的函數(shù)
AVG – 該函數(shù)返回指定列的平均值
SUM –該函數(shù)把指定的列中的數(shù)字加起來
MIN – 該函數(shù)返回列中最小的非NULL值
MAX –該函數(shù)返回列中的最大值
GROUP BY – 按列匯集查詢函數(shù)結(jié)果的子句
8.Oracle數(shù)據(jù)直接導(dǎo)出到文本文件的方法
利用Oracle中的Spool緩沖池技術(shù)可以實(shí)現(xiàn)Oracle數(shù)據(jù)導(dǎo)出到文本文件。
1)、在Oracle PL/SQL中輸入緩沖開始命令,并指定輸出的文件名:
spool d:output.txt
2)、在命令行中隨便輸入你的SQL查詢:
select mobile from customer;
select mobile from client;
……
3)、在命令行中輸入緩沖結(jié)果命令:
spool off;
則系統(tǒng)將緩沖池中的結(jié)果都輸出到"output.txt"文件中。
以TAB鍵分隔