Menu
Woocommerce Menu

个个效率不一样,2.查询数据库job语句

0 Comment

sql多表联查实例下面提供四款sql多表关联查询的实例,个个效率不一样。

1.查询dblink语句

sql多表联查实例下面提供四款sql多表关联查询的实例,个个效率不一样。select
* from order_info as a ,ivrlog4ivrdlvinst as b where
(a.saleorder=b.ext1_skill and b.start_date=@date1 and se_id=’55’ and
b.ext1_skill!=”) and convert(varchar(10),a.instime,112)=@date2 and
max(a.instime)

col owner for a20
col db_link for a30
col username for a20
col host for a30
set linesize 120
set pages 60
select * from dba_db_links order by owner;

方法二

 

select * from order_info as a where a.saleorder=( select b.ext1_skill
from ivrlog4ivrdlvinst as b where b.start_date=@date1 and se_id=’55’
and b.ext1_skill!=”)and convert(varchar(10),max(a.instime),112)=@date2

2.查询数据库job语句

方法三

alter session set nls_date_format=’YYYY-MM-DD HH24:MI:SS’;
col owner for a20
col job_name for a30
col LAST_START_DATE for a20
col NEXT_RUN_DATE for a20
col job_action for a40
col what for a40
col status for a10
set linesize 200
set pages 100

declare @date1 varchar(20), @date2 varchar(20) set @date1=’20100812′ set
@date2=’2010-08-12′

select * from (with a as
(select log_Date, job_name, status
from ALL_SCHEDULER_JOB_LOG l
where owner not in (‘SYS’,’SYSTEM’,’SYSMAN’)),
b as
(select job_name, max(log_date) m_date
from ALL_SCHEDULER_JOB_LOG l
where owner not in (‘SYS’,’SYSTEM’,’SYSMAN’)
group by job_name),
c as
(select j.owner,
j.job_name,
j.last_start_date,
j.next_run_date,
j.JOB_ACTION
from all_scheduler_jobs j
where j.owner not in (‘SYS’,’SYSTEM’,’SYSMAN’))
select c.owner,
a.job_name,
to_char(c.LAST_START_DATE, ‘yyyy-mm-dd hh24:mi:ss’)
LAST_START_DATE,
to_char(c.NEXT_RUN_DATE, ‘yyyy-mm-dd hh24:mi:ss’) NEXT_RUN_DATE,
c.job_action,
a.status,
sysdate “search_date”
from a, b, c
where a.job_name = b.job_name
and a.job_name = c.job_name
and a.log_date = b.m_date)
union all
select schema_user,
to_char(job) “job_name”,
to_char(last_date, ‘yyyy-mm-dd hh24:mi:ss’) “LAST_DATE”,
to_char(next_date, ‘yyyy-mm-dd hh24:mi:ss’) “NEXT_DATE”,
what,
case
when failures = 0 then
‘SUCCEEDED’
else
‘FAILED’
end case,
sysdate
from dba_jobs
where schema_user not in (‘SYS’,’SYSTEM’,’SYSMAN’) and broken = ‘N’;

select * from order_info as a where a.saleorder=(select b.ext1_skill
from ivrlog4ivrdlvinst as b where b.start_date=@date1 and se_id=’55’
and b.ext1_skill!=”) and convert(varchar(10),a.instime,112)=@date2 and
max(a.instime)

 

方法四

3.查询表空间使用率和数据文件碎片

select b.caller, b.start_date, b.start_time, b.ext1_skill,
c.deliveryno, c.destroyresult, c.deliverydate, c.deliverytime,
c.arrangetime, c.driverphone, c.drivermobile, a.servicedate,
a.servicetime, a.workertelfrom order_info as a ,ivrlog4ivrdlvinst as b
,delivery_info as cwhere a.saleorder in (select b.ext1_skill from
ivrlog4ivrdlvinst where b.start_date=@date1 and b.se_id=’55’ and
b.ext1_skill!=”) and convert(varchar(10),a.instime,112)=@date2 order
by b.start_date desc, b.start_time desc

普通表空间:

col total_mb for 999999
col free_mb for 99999
col free_rate for a15
col used_rate for a15

select d.tablespace_name,
d.mb total_mb,
f.mb free_mb,
round((f.mb / d.mb), 4) * 100 || ‘%’ free_rate,
round((d.mb – f.mb) / d.mb, 4) * 100 || ‘%’ used_rate
from (select tablespace_name, bytes / 1024 / 1024 mb from
dba_data_files) d,
(select tablespace_name, sum(bytes) / 1024 / 1024 mb
from dba_free_space
group by tablespace_name) f
where d.tablespace_name = f.tablespace_name(+)
order by (d.mb – f.mb) / d.mb desc;

临时表空间:

SELECT A.tablespace_name tablespace,
D.mb_total,
SUM(A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total – SUM(A.used_blocks * D.block_size) / 1024 / 1024
mb_free
FROM v$sort_segment@ncslave.com A,
(SELECT B.name, C.block_size, SUM(C.bytes) / 1024 / 1024 mb_total
FROM v$tablespace@ncslave.com B, v$tempfile@ncslave.com C
WHERE B.ts# = C.ts#
GROUP BY B.name, C.block_size) D
WHERE A.tablespace_name = D.name GROUP by A.tablespace_name,
D.mb_total;

 

数据文件碎片:

select file_name,
ceil((nvl(hwm, 1) * 8192) / 1024 / 1024 / 1024) smallest,
ceil(blocks * 8192 / 1024 / 1024 / 1024) currsize,
ceil(blocks * 8192 / 1024 / 1024 / 1024) –
ceil((nvl(hwm, 1) * 8192) / 1024 / 1024 / 1024) savings
from dba_data_files a,
(select file_id, max(block_id + blocks – 1) hwm
from dba_extents
group by file_id) b
where a.file_id = b.file_id(+);

 

4.查询数据库死锁

alter session set nls_date_format=’yyyy-mm-dd hh24:mi:ss’;
col oracle_username for a15
col os_user_name for a15
col object_name for a30
col machine for a20
set linesize 150
set pages 100

SELECT l.session_id sid,
s.serial#,l.oracle_username,l.os_user_name,s.machine,o.object_name,
s.logon_time FROM v$locked_object l, all_objects o, v$session s WHERE
l.object_id = o.object_id AND l.session_id = s.sid and
s.status<>’ACTIVE’ ORDER BY sid, s.serial#;

杀掉僵死会话:

alter system kill session ‘sid,serial#’ immediate;

 

5.闪回查询

SELECT * FROM  
(SELECT * FROM comp_rs_ins_comp as of 
timestamp (to_date(‘2014-12-2 15:50:00′,’yyyy-mm-dd hh24:mi:ss’)) )
WHERE comp_rs_ins_id in (‘5030933252’);

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章

网站地图xml地图