oracle 查詢語句集合

2021-08-31 15:29:30 字數 1748 閱讀 1695

整理了下這兩天用到的oracle 查詢語句,作為記錄。

1,查詢當前使用者所有的表資訊

select * from user_tables order by table_name;

2,查詢表空間的使用情況

select   a.tablespace_name,a.bytes/1024/1024 "sum mb",(a.bytes-b.bytes)/1024/1024   "used mb",b.bytes/1024/1024 "free mb",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"  

from  

(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name)   a,  

(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name)   b  

where   a.tablespace_name=b.tablespace_name  

order   by   ((a.bytes-b.bytes)/a.bytes)   desc  ;

3,檢視使用者表、索引、分割槽表占用空間

select segment_name, sum(bytes)/1024/1024 mbytese from user_segments  group by segment_name;

3.1、表占用空間

select segment_name, sum(bytes)/1024/1024 mbytese from user_segments where segment_type='table'  group by segment_name order by ( sum(bytes)/1024/1024) desc;

3.2、索引占用空間

select segment_name ,sum(bytes)/1024/1024 from user_segments where segment_type ='index' group by segment_name;

3.3、分割槽表table partition占用空間

select segment_name,sum(bytes)/1024/1024 mbytes  from user_segments where segment_type='table partition' group by segment_name; 

4,設定給指定的表空間增加資料檔案

alter tablespace tablespacename  add datafile 'f:\oracle\product\10.2.0\oradata\eas0304\eas_d_eas_standard06.dbf' size 10g;

5,查詢表空間的磁碟碎片

select tablespace_name,count(*) chunks ,max(bytes/1024/1024) max_chunk 

from dba_free_space group by tablespace_name;

oracle集合查詢

集合操作符專門用於合併多條select 語句的結果,包括 union,union all,intersect minus。當使用集合操作符時,必須確保不同查詢的列個數和資料型別匹配。集合操作符具有以下注意事項 集合操作符不適用於lob varray和巢狀表列。union intersect minu...

Oracle 集合查詢

1 並集運算 union 注意 union 二個集合中,如果都有相同的,取其一 union all 二個集合中,如果都有相同的,都取出來。例 使用並集運算,查詢20號或30號部門的員工資訊。select from emp where deptno 30 union select from emp w...

Oracle查詢語句

select sysdate from dual dual 臨時的表,使語法結構完整,沒有什麼意義。oracle中的select語句必須要有from 而sql2008中可以沒有。起別名 起別名 as起別名,不用加雙引號.加空格起別名,要加雙引號 select name as 姓名 from stud...