目录
1、查看临时表空间使用率
2、查看表空间使用率
3、查询物理文件使用情况
4、查询某个表属于哪个表空间
5、查询每个表占用的空间
6、查看某个表空间里包含哪些表
7、查询oracle正在执行的sql
8、查询每个表的创建时间
9、查看oracle正在执行的或执行过的sql
10、查看sql执行时间
11、Oracle 获取上周一到周末日期的查询sql语句
SELECT
a.tablespace_name,
a.BYTES total,
a.bytes - NVL(b.bytes, 0) free
FROM
( SELECT
tablespace_name,
SUM (bytes) bytes
FROM
dba_temp_files
GROUP BY
tablespace_name) a,
( SELECT
tablespace_name,
SUM (bytes_cached) bytes
FROM
v$temp_extent_pool
GROUP BY
tablespace_name) b
WHERE
a.tablespace_name = b.tablespace_name(+)
SELECT
dbf.tablespace_name,
dbf.totalspace "总量(M)",
dbf.totalblocks AS 总块数,
dfs.freespace "剩余总量(M)",
dfs.freeblocks "剩余块数",
(dfs.freespace / dbf.totalspace) * 100 "空闲比例"
FROM
( SELECT
t.tablespace_name,
SUM(t.bytes) / 1024 / 1024 totalspace,
SUM(t.blocks) totalblocks
FROM
dba_data_files t
GROUP BY
t.tablespace_name) dbf,
( SELECT
tt.tablespace_name,
SUM(tt.bytes) / 1024 / 1024 freespace,
SUM(tt.blocks) freeblocks
FROM
dba_free_space tt
GROUP BY
tt.tablespace_name) dfs
WHERE
trim(dbf.tablespace_name) = trim(dfs.tablespace_name)
select
b.file_name 物理文件名,
b.tablespace_name 表空间,
b.bytes/1024/1024 大小M,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M,
substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)*100,1,5) 利用率
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.bytes
order by b.tablespace_name
select table_name,tablespace_name from user_tables where table_name='表名';
SELECT
t.segment_name,
t.segment_type,
SUM(t.bytes / 1024 / 1024) "占用空间(M)"
FROM
dba_segments t
WHERE
t.segment_type='TABLE'
GROUP BY
OWNER,
t.segment_name,
t.segment_type;
Select Table_Name, Tablespace_Name From Dba_Tables Where Tablespace_Name = '表空间名称';
方法一:
SELECT
b.sid oracleID,
b.username 登录Oracle用户名,
b.serial#,
spid 操作系统ID,
paddr,
sql_text 正在执行的SQL,
b.machine 计算机名
FROM
v$process a,
v$session b,
v$sqlarea c
WHERE
a.addr = b.paddr
AND b.sql_hash_value = c.hash_value
方法二:
SELECT
a.username,
a.sid,
b.SQL_TEXT,
b.SQL_FULLTEXT
FROM
v$session a,
v$sqlarea b
WHERE
a.sql_address = b.address
SELECT
object_name,
object_type,
created
FROM
all_objects
WHERE
owner='所属用户替换为自己的'
AND object_type='TABLE'
ORDER BY
created DESC;
正在执行的sql
SELECT
a.username,
a.sid,
b.SQL_TEXT,
b.SQL_FULLTEXT
FROM
v$session a,
v$sqlarea b
where a.sql_address = b.address
SELECT
b.sid oracleID,
b.username 登录Oracle用户名,
b.serial#,
spid 操作系统ID,
paddr,
sql_text 正在执行的SQL,
b.machine 计算机名
FROM
v$process a,
v$session b,
v$sqlarea c
WHERE
a.addr = b.paddr
AND b.sql_hash_value = c.hash_value
执行过的sql
SELECT
b.SQL_TEXT,
b.FIRST_LOAD_TIME,
b.SQL_FULLTEXT
from v$sqlarea b
where b.FIRST_LOAD_TIME BETWEEN '查询的时间范围--开始时间' AND '查询的时间范围--结束时间'
ORDER BY
b.FIRST_LOAD_TIME
SELECT
sid "SID",
ELAPSED_SECONDS "秒 已经执行",
TIME_REMAINING "秒 预计完成时间",
jindu "进度",
SQL_TEXT
FROM
(
SELECT
A.USERNAME,
A.SID,
A.SERIAL#,
A.OPNAME,
a.TARGET,
a.START_TIME,
a.last_update_time,
C.OSUSER,
C.MACHINE,
C.PROGRAM,
ROUND(A.SOFAR * 100 / TOTALWORK, 0) || '%' AS jindu,
A.TIME_REMAINING,
a.ELAPSED_SECONDS,
B.SQL_TEXT
FROM
gV$SESSION_LONGOPS A,
gV$SQL B,
gV$SESSION C
WHERE
A.SQL_ADDRESS = B.ADDRESS
AND A.SQL_HASH_VALUE = B.HASH_VALUE
AND A.SID = C.SID
AND C.STATUS = 'ACTIVE'
-- AND a.ELAPSED_SECONDS > 1
--AND a.last_update_time BETWEEN TRUNC (SYSDATE) + 9 / 24
-- AND TRUNC (SYSDATE) + 21 / 24
)
WHERE
jindu != '100%';
1、获取当期时间是该周内的第几天
select to_char(to_date('20130906','yyyymmdd'),'d') from dual;
是以周日为开始计算的。结果:6 注释:2013.09.06是周五,为本周的第六天
2、获取上周几的日期
select trunc(sysdate,'iw') - 7 from dual;---上周一
select trunc(sysdate,'iw') - 1 from dual;--上周日
3、查询得到的是本周一的时间
select trunc(sysdate,'iw') from dual;