Oracle常用sql语句(查询数据库中锁表、查询数据库表字段总数)

时间:2022-01-06 23:22:41

--查询数据库中被锁住的表
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;