【ORACLE】oracle的一些操作記錄

最近一個月外出支援

做數據遷移

之前不怎麼使用oracle,也是現學現用的  ,這過程中發現oracle真心強大,比mysql強好多

 

期間寫了一些sql,現在保存一下,權當模板了

 

 

 

查看操作進程的剩餘時間(第一句):

SELECT c.STATUS,time_remaining/60 剩餘時間分鐘,sql_text 執行SQL,machine,message
FROM V$SESSION_LONGOPS a inner join v$sql b on
a.sql_hash_value = b.hash_value
inner join v$session c on a.sid = c.sid
where sofar<totalwork
order by time_remaining desc

select sid,message,time_remaining, start_time,last_update_time,elapsed_seconds from V$SESSION_LONGOPS where time_remaining>0;

select sid,message,time_remaining, start_time,last_update_time,elapsed_seconds from V$SESSION_LONGOPS Order By start_time Desc

select sid,message,time_remaining, start_time,last_update_time,elapsed_seconds from V$SESSION_LONGOPS Order By last_update_time Desc;

 

 

查看被鎖的表:

select object_name,machine,s.sid,s.serial#
from v$locked_object l,dba_objects o ,v$session s
where l.object_id = o.object_id and l.session_id=s.sid;

 

 

解鎖

alter system kill session '139,213';

 

 

select * from gv$process
where addr in (
select paddr from gv$session where sid =72);

 


Select * from  v$session_wait where sid=139

SELECT sid, total_waits, time_waited
FROM v$session_event
WHERE event='db file sequential read' And sid=72  and total_waits>0;

select t2.username,t2.sid,t2.serial#,t2.logon_time
from v$locked_object t1,v$session t2
where t1.session_id=t2.sid order by t2.logon_time;

 

 

 

創建序列:

-- Create sequence
create sequence xulie
minvalue 1
maxvalue 9999999999999999999999999999
start with 11602214
increment by 1
cache 20
cycle;

 

xulie.Nextval

 

創建索引:

Create Index 名字On tablename(字段);

 

刪除索引:

drop index 名字

 

 

 

一些基本的語句:

Update tableA a Set aaa=(Select bbbFrom tableB b Where a.id=b.id);

 

Update tableA a Set aaa=(a.aaa||'0') ;

 

 

Insert Into t_nota_apply_user(   ) Select   From aaa  ;

 

 

 

Update aaaaa Set OLDSTATUS=-1 Where oid In(Select Max(oid) From aaa Group By a, b Having Count(1)>1)
Update aaaaa Set OLDSTATUS=-1 Where oid In(Select Max(oid) From aaa Group By a, b Having Count(1)=1)

 

 

Select * From aaaa a Inner Join  bbbbb b On a.id=b.id

 

Select Sum(amount) As totalmount,id,code From aaaaa  Group By id,code

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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