太陽雨

          痛并快樂著

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            67 Posts :: 3 Stories :: 33 Comments :: 0 Trackbacks
          1、單獨備份一個或多個用戶:
          D:>exp scott/tiger file=導出文件
          D:>exp system/manager owner=(用戶1,用戶2,…,用戶n) file=導出文件

          2、單獨備份一個或多個表:
          D:>exp 用戶/密碼 tables=表
          D:>exp 用戶/密碼 tables=(表1,…,表2)
          D:>exp system/manager tables=(用戶.表)
          D:>exp system/manager tables=(用戶1.表1,用戶2.表2)

          3、導入指定表
          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
          (說明:如果導出用戶沒有DBA權限,則導入用戶可以不用指定fromuser、touser參數如果導出用戶擁有DBA權限,則導入用戶也必須擁有DBA權限)

          4、給表、列加注釋
          SQL>comment on table 表 is '表注釋';
          注釋已創建。
          SQL>comment on column 表.列 is '列注釋';
          注釋已創建。
          SQL> select * from user_tab_comments where comments is not null;
          SQL> select * from user_col_comments where comments is not null;

          5、查看當前用戶下有什么對象(表、視圖、同義詞、快照)
          SQL> select * from tab;
          查看表結構
          SQL> describe 表名
          簡寫以上命令
          SQL> desc 表名

          6、
          DDL、數據定義語言:create、alter、drop、truncate(創建、修改結構、刪除、截斷)(其他:rename)
          DML、數據操縱語言:insert、delete、select、update(增、刪、查、改)
          DCL、數據控制語言:grant、revoke(授權、回收)、set role
          事務控制:commit、rollback、savepoint(其他:lock table、set constraint(s)、set transaction)
          審計控制:audit、noaudit
          系統控制:alter system
          會話控制:alter session
          其他語句:comment(添加注釋)、explain plan、analyze(收集統計)、validate、call

          7、
          1)、查看當前所有對象
          SQL> select * from tab;

          2)、建一個和a表結構一樣的空表
          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)、察看數據庫的大小,和空間使用情況
          SQL> col tablespace format a20
          SQL> select b.file_id 文件ID,
          b.tablespace_name 表空間,
          b.file_name 物理文件名,
          b.bytes 總字節數,
          (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 --數據文件空間占用情況

          4)、查看現有回滾段及其狀態
          SQL> col segment format a30
          SQL> SELECT SEGMENT_NAME,OWNER,TABLESPACE_NAME,SEGMENT_ID,FILE_ID,STATUS FROM DBA_ROLLBACK_SEGS;

          5)、查看數據文件放置的路徑
          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)、顯示當前連接用戶
          SQL> show user

          7)、把SQL*Plus當計算器
          SQL> select 100*20 from dual;

          8)、連接字符串
          SQL> select 列1||列2 from 表1;
          SQL> select concat(列1,列2) from 表1;

          9)、查詢當前日期
          SQL> select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss') from dual;

          10)、用戶間復制數據
          SQL> copy from user1 to user2 create table2 using select * from table1;

          11)、視圖中不能使用order by,但可用group by代替來達到排序目的
          SQL> create view a as select b1,b2 from b group by b1,b2;

          12)、通過授權的方式來創建用戶
          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的函數
          ORDER BY – 按照指定列排序返回結果的子句
          DISTINCT – 只返回結果集合內唯一行的關鍵詞
          COUNT -- 返回匹配查詢的數據行總數數值的函數
          AVG – 該函數返回指定列的平均值
          SUM –該函數把指定的列中的數字加起來
          MIN – 該函數返回列中最小的非NULL值
          MAX –該函數返回列中的最大值
          GROUP BY – 按列匯集查詢函數結果的子句

          8.Oracle數據直接導出到文本文件的方法
          利用Oracle中的Spool緩沖池技術可以實現Oracle數據導出到文本文件。
          1)、在Oracle PL/SQL中輸入緩沖開始命令,并指定輸出的文件名:
          spool d:output.txt

          2)、在命令行中隨便輸入你的SQL查詢:
          select mobile from customer;
          select mobile from client;
          ……

          3)、在命令行中輸入緩沖結果命令:
          spool off;
          則系統將緩沖池中的結果都輸出到"output.txt"文件中。
          以TAB鍵分隔
          posted on 2008-12-22 11:56 小蟲旺福 閱讀(202) 評論(0)  編輯  收藏 所屬分類: 數據庫
          主站蜘蛛池模板: 大连市| 封开县| 正阳县| 永宁县| 天水市| 六盘水市| 南陵县| 无极县| 定南县| 宾阳县| 金门县| 沂水县| 定西市| 墨玉县| 孟连| 新余市| 浦江县| 如东县| 桂阳县| 卢氏县| 诏安县| 屯门区| 镇平县| 天镇县| 南陵县| 同心县| 福清市| 武定县| 连州市| 鄂尔多斯市| 大田县| 平远县| 林芝县| 双城市| 邳州市| 衡阳县| 仁怀市| 察隅县| 工布江达县| 苗栗县| 鄂托克前旗|