1.查询高于平均价格的商品名称:
select item_name from ebsp.product_market_price where item_price > (select avg(item_price) from ebsp.product_market_price
2.oracle9i以上版本,可以实现将某张表的数据同时插入到多张表中。例:
复制代码 代码如下:
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语句变为insert first 后面不变,当使用first操作符执行多表插入时,如果数据已经满足了先前的条件,并且已经被插入到某表中,那么该行数据在后续的插入中将不会被再次使用。
3.截取字符串制定的长度。
复制代码 代码如下:
select substr(item_name,0,2) from ebsp.product_market_price
select substr(‘ho鲜红的鲜花 ‘,0,3) from dual; –print ‘ho鲜’
获得emp系统表中hiredate雇佣日期,有重复的记录,也就是一天中雇佣多名员工的记录。
复制代码 代码如下:
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存入数据库中时日期型带有时分秒,可以通过to_char(create_date, ‘yyyy-mm-dd’)来代替上面的
4.修改oracle数据库缓存大小,以system登陆:
复制代码 代码如下:
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;