本人搜集的一些常用的SQL查詢語句(不定期更新)

來源:互聯網
上載者:User

****************
TABLESPACE
****************

#查看錶空間建立過程
set long 9999
select dbms_metadata.get_ddl('TABLESPACE','EXAMPLE') from dual;

#查詢單個資料表空間的使用率
SELECT sysdate,a.tablespace_name "資料表空間名",
       round(total / 1024 / 1024 / 1024, 3) "資料表空間大小(GB)",
       round(free / 1024 / 1024 / 1024, 3) "資料表空間剩餘大小(GB)",
       round((total - free) / 1024 / 1024 / 1024, 3) "資料表空間使用大小(GB)",
       ROUND((total - free) / total, 4) * 100 "使用率 %"
  FROM (SELECT tablespace_name, SUM(bytes) free
          FROM DBA_FREE_SPACE
         GROUP BY tablespace_name) a,
       (SELECT tablespace_name, SUM(bytes) total
          FROM DBA_DATA_FILES
         GROUP BY tablespace_name) b
 WHERE a.tablespace_name = b.tablespace_name
 order by 4 DESC;

*****
ASM
*****

BEGIN
DBMS_FILE_TRANSFER.COPY_FILE(
SOURCE_DIRECTORY_OBJECT=>'$S_DIR',
SOURCE_FILE_NAME=>'$1',
DESTINATION_DIRECTORY_OBJECT=>'$D_DIR',
DESTINATION_FILE_NAME=>'$1');
END;

ASM檔案拷貝到本地
現在使用ASM的使用者越來越多了,而ASM最不方便的就是所有的檔案都在oracle自己管理的系統裡。我們碰到需要將某個檔案拷貝出來的時候就比較麻煩,可能要依賴於RMAN,發現有個方法可以用:

登入ORACLE資料庫伺服器
1 create or replace directory SOURCE_DIR as '+DATADG/sfoss/onlinelog/';
2 create or replace directory ORACLE_DEST as '/tmp/oralog/dest';
3 BEGIN
dbms_file_transfer.copy_file(source_directory_object =>'SOURCE_DIR', source_file_name => 'group_1.257.695065683',destination_directory_object => 'ORACLE_DEST',destination_file_name => 'redo_1.log');
END;
/
這樣今後就不怕從ASM裡拷貝任何檔案出來了

**************************
NLS_CHARACTERCET
**************************

#查看資料庫字元集
SQL> select property_name,property_value from database_properties where property_name='NLS_CHARACTERSET';

#查使用者語言環境變數和資料庫字元集
SQL> select userenv('language') from dual;

Gbk中一個中文佔用2個字元,而utf8中一個中文佔用3個字元,所以從gbk匯入utf8的表欄位可能超長,導致出錯。
SQLPLUS環境變數也要設定成UTF8
$export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"

impdp加“TABBLE_EXISTS_ACTION=TRUNCATE”

***********************
NLS_DATE_FORMAT
***********************
#修改系統日期時間格式
1.在.bash_profile中增加一句:export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
(注意:要生效必須在前面再加一句:export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK或export NLS_LANG=AMERICAN)
2.在SQLPLUS的glogin.sql中增加一句:SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'
3.修改當前會話的日期格式:SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'
4.修改資料庫參數,需要重啟生效:SQL> alter system set nls_date_format='yyyy-mm-dd hh24:mi:ss' scope=spfile;

***********
v$session
***********
SQL> select sid, serial#, username,status
  from v$session
 where sid in (select blocking_session from v$session);

***********************
v$recovery_file_dest
***********************
SQL> select name,floor(space_limit/1024/1024) "size MB",
seil(space_used/1024/1024) "used MB"
from v$recovery_file_dest order by name;

**********************
v$session_longops
**********************
SQL> select sid,serial#,context,sofar,totalwork,round(sofar/totalwork*100,2) "%_complete" from v$session_longops where opname like 'RMAN%';

-------------------------------------------------------------------------------------------------------

By aaron8219 Chinaunix Blog:http://blog.chinaunix.net/uid/24612962.html

原創內容,轉載請註明連結,謝謝!

http://blog.csdn.net/aaron8219/article/details/10056055

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.