欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

oracle學(xué)習(xí)筆記(二)

 更新時(shí)間:2011年12月28日 22:43:35   作者:  
最近需要用的oracle,所以大家好好的學(xué)習(xí)下基礎(chǔ)并整理下資料,希望能幫助到需要的朋友。

一、多行函數(shù)又稱組合函數(shù)(Group Functions)、聚合函數(shù)

1、 Types of Group Functions
avg、count、max、min、stddev、sum、variance
avg 求平均數(shù)
select avg(nvl(列1,0)) from 表1
count求行數(shù)
在where條件中不允許使用聚合函數(shù),但可以使用having avg(列1)>1000
having所起的作用和where一樣

二、子查詢Subqueries

查詢前10行數(shù)據(jù)
oracle: select * from 表名 where rownum<=10;
sql: select top 10 * from 表名
單行子查詢
select * from 表1 where 工資列1>(select avg(工資列1) from 表1)
多行子查詢
select * from 表1 where 工資列1 in(select min(工資列1) from 表1 group by 部門列)

三、自定義變量

set verify on/off
show all
help show/set

column lie justify left

四、數(shù)據(jù)操作語句

1、insert插入語句
向表2里插入數(shù)據(jù)
oracle:insert into (select 列1,列2 from 表2)values('XXX','XXX');
oracle/sql:insert into(列1,列2)values('XXX','XXX');
從另一個(gè)表里復(fù)制數(shù)據(jù)
oracle/sql:insert into 表(列1,列2)select 列1,列2 from 表2

2、update語句
都為: update table set column1='...'[ ,column2='...'] where ...
嵌入子查詢的修改
update table set column1=(select column2 form table where columnid=1) where column1='...'

delete刪除語句
delete [from] table [where condition]

merge 合并語句
oracle:
merge into 表1 a using 表2 b on (a.id=b.id)
when matched then
update set
a.name=b.name,
a.other=b.other
when not matched then
insert values(b.id,b.name,b.other);
sql:合并insert,update
方法1:
declare @ROWCOUNT int
set @ROWCOUNT=(select count(*) from tb_name where name1='5')
if @ROWCOUNT!=0
update tb_name set name2='55555555' where name1='5'
else
insert into tb_name(name1,name2) values('5','插入')
方法2:
update tb_name set name2='55555555' where name1='6'
if @@ROWCOUNT=0
insert into tb_name(name1,name2) values('6','插入')

五,事務(wù): 隱式、顯式的事務(wù)

commit提交事務(wù)
rollback 回滾事務(wù)
locking鎖
對(duì)并發(fā)性系統(tǒng)自動(dòng)加鎖,事務(wù)提交后、或回滾后自動(dòng)解鎖。

相關(guān)文章

最新評(píng)論