1.查詢高于平均價(jià)格的商品名稱:
SELECT item_name FROM ebsp.product_market_price WHERE item_price > (SELECT AVG(item_price) FROM ebsp.product_market_price
2.oracle9i以上版本,可以實(shí)現(xiàn)將某張表的數(shù)據(jù)同時(shí)插入到多張表中。例:
復(fù)制代碼 代碼如下:
INSERT ALL
WHEN deptno=10 THEN INTO dept10 --部門編號為10的插入表dept10中
WHEN deptno=20 THEN INTO dept20
WHEN deptno=30 THEN INTO dept30
WHEN job='CLERK' THEN INTO clerk --崗位為CLERK的插入表clerk 中
ELSE INTO other
SELECT * FROM emp;
可以將前面的sql語句變?yōu)镮NSERT FIRST 后面不變,當(dāng)使用First操作符執(zhí)行多表插入時(shí),如果數(shù)據(jù)已經(jīng)滿足了先前的條件,并且已經(jīng)被插入到某表中,那么該行數(shù)據(jù)在后續(xù)的插入中將不會(huì)被再次使用。
3.截取字符串制定的長度。
復(fù)制代碼 代碼如下:
select substr(item_name,0,2) from ebsp.product_market_price
select substr(‘ho鮮紅的鮮花 ',0,3) from dual; --print ‘ho鮮'
獲得emp系統(tǒng)表中hiredate雇傭日期,有重復(fù)的記錄,也就是一天中雇傭多名員工的記錄。
復(fù)制代碼 代碼如下:
SQL1: select * from scott.emp where hiredate in (select hiredate mycount from scott.emp group by hiredate having count(*) >1)
SQL2:select t2.* from scott.emp t2 ,
(select t.hiredate,count(*) mycount from scott.emp t group by t.hiredate having count(*) >1) t1
where t2.hiredate = t1.hiredate
如果hiredate存入數(shù)據(jù)庫中時(shí)日期型帶有時(shí)分秒,可以通過to_char(CREATE_DATE, 'YYYY-MM-DD')來代替上面的
4.修改oracle數(shù)據(jù)庫緩存大小,以system登陸:
復(fù)制代碼 代碼如下:
alter system set db_cache_size = 700m scope = spfile;
alter system set shared_pool_size = 200m scope=spfile;
alter system set pga_aggregate_target = 100m scope=spfile;