Oracle常用sql語句(查詢數據庫中鎖表、查詢數據庫表字段總數)

--查詢數據庫中被鎖住的表
Select c.sid,c.serial#,d.name,b.object_name,c.username,c.program,c.osuser
from gv$Locked_object a, All_objects b, gv$session c, audit_actions d
where a.object_id = b.object_id and a.inst_id = c.inst_id(+) and a.session_id = c.sid(+)
and c.command = d.action;


--解除數據庫中被鎖住的表(SID,SERIAL)
alter system kill session '75,1989';


--查詢數據庫表字段總數
select count(0) from user_col_comments where table_name = upper('fl_sys_log');


--查詢字符串長度(第一個按字符長度計算,第二個是按字節計算)
select length('a大b中國'),lengthb('a大b中國') from dual;

 

--同表中,存在重複記錄時,刪除其中一條

delete from tablename a where rowid!=(select min(rowid) from tablename b where a.columnId=b.columnId)
 

--刪除物化視圖
drop materialized view log on fl_rent_payplan(創建物化視圖的基表名稱);--首先刪除日誌文件
drop materialized view MV_HXMX(物化視圖名稱);

--命令窗口下,打開輸出日誌
set serveroutput on;

--將所有的系統權限賦值給某用戶
grant all privileges to username;

--創建表空間
create tablespace lg  
 datafile '/u01/app/oracle/oradata/orcl/lg.dbf' size 1g;  

--改變表空間大小
alter database datafile '/u01/app/oracle/oradata/orcl/lg.dbf' resize 3072m;

--查看錶空間是否自動增長
SELECT FILE_NAME,TABLESPACE_NAME,AUTOEXTENSIBLE FROM dba_data_files;

--打開表空間自動增長
alter database datafile '/u01/app/oracle/oradata/orcl/lg.dbf' autoextend on;

--每次自動增長200m
alter database datafile '/u01/app/oracle/oradata/orcl/lg.dbf' autoextend on next 200M;

--每次自動增長200m,數據表最大不超過1G
alter database datafile '/u01/app/oracle/oradata/orcl/lg.dbf' autoextend on next 200M maxsize 1024M;

--查看各表空間分配情況
select tablespace_name, sum(bytes) / 1024 / 1024  from dba_data_files group by tablespace_name;

-查看各表空間空閒情況
select tablespace_name, sum(bytes) / 1024 / 1024  from dba_free_space  group by tablespace_name; 

 

發佈了24 篇原創文章 · 獲贊 14 · 訪問量 31萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章