天天看點

oracle資料庫表字段查詢語句,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;