1.限制返回記錄的行數(4-10行)
select rownum,c1 from t144 where rownum<10
minus
select rownum,c1 from t144 where rownum<5
2.批量插入
insert into tablename(select * from othertable)
或insert into (column1,column2,,,,,,,)tablename(select column1,column2,,,,,,,from othertable)
3,分組函式(結果中出現的列要在group by 中出現)
select count(age), username, , ,... from table group by age,usename,,,,...
4.檢視資料庫中的存在的表
select table_name from dba_tables (include all users)
select * from tab(include view)
5.高效update,一次修改多個列
update smsmonitor sms
set (sms.smsmonitor_sendflag, sms.smsmonitor_maxnum) = (select s.smsmonitor_sendflag,
s.smsmonitor_maxnum
from smsmonitor s
where s.smsmonitor_id =
'i74668')
where sms.smsmonitor_id = 'i74669'
6,高效刪除表中重覆記錄
delete from emp e
where e.rowid > (select min(x.rowid)
from emp x
where x.emp_no = e.emp_no);
7.如何定位重要(消耗資源多)的sql
select sql_text
from v$sql
where disk_reads > 1000 or (executions > 0 and buffer_gets/executions > 30000);
8.如何跟蹤某個session的sql
exec dbms_system.set_sql_trace_in_session(sid,serial#,&sql_trace);
select sid,serial# from v$session where sid = (select sid from v$mystat where rownum = 1);
exec dbms_system.set_ev(&sid,&serial#,&event_10046,&level_12,'');
8,mysql中欄位操作
增加字段
alter table name add code char(200) default 0
刪除字段
alter table table_name drop column column_name
修改字段型別
alter table table_name alter column column_name new_data_type
新增主鍵字段
alter table tb add 列名 int primary key default 0
查詢被鎖住的sql語句
select /*+ rule */ s.username,
decode(l.type,'tm','table lock',
'tx','row lock',
null) lock_level,
o.owner,o.object_name,o.object_type,
s.sid,s.serial#,s.terminal,s.machine,s.program,s.osuser
from v$session s,v$lock l,dba_objects o
where l.sid = s.sid
and l.id1 = o.object_id(+)
and s.username is not null
解鎖表--alter system kill session 'sid,serial#';
--把鎖給kill掉
alter system kill session '146,21177';
解鎖使用者sql
alter user username account unlock;
根據索引名稱查詢該索引所在的表資訊
select table_name from all_indexes where index_name='dchnbaccfeedet_pk'
查詢該索引的資訊
select * from all_objects where object_name like 'dchnbaccfeedet_pk'
sql常用sql語句
1 查詢某個庫中所有的表名字 select name from sysobjects where xtype u and name dtproperties order by name 2 得到資料庫中所有使用者檢視 select name from sysobjects where xtype v...
常用sql語句
t sql語句複製表的方法 我在sql server 2000中有現個資料庫datahr及demo,它們的結構是一樣,其它有乙個表名為 gbitem.現在我想將demo資料庫的表名 gbitem的全部內容複製到datahr資料庫的表名為 gbitem中。請問此t sql語句應該怎麼寫?謝謝高人指點!...
常用SQL語句
查詢 sp who 中的結果值。因為儲存過程不能查詢,先轉為臨時表再查詢。declare tb table spid varchar 100 ecid varchar 100 status varchar 100 loginame varchar 100 hostname varchar 100 b...