云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Oracle面试题集锦

Oracle面试题集锦

  • 62 次阅读
  • 3 次下载
  • 2025/5/4 0:47:08

select count(*) from sc;

40. 查询选修“叶平”老师所授课程的学生中,成绩最高的学生姓名及其成绩 select Student.Sname,score from Student,SC,Course C,Teacher where

Student.S#=SC.S# and SC.C#=C.C# and C.T#=Teacher.T# and Teacher.Tname='叶平' and SC.score=(select max(score)from SC where C#=C.C# ); 41. 查询各个课程及相应的选修人数

select count(*) from sc group by C#;

42. 查询不同课程成绩相同的学生的学号、课程号、学生成绩

select distinct A.S#,B.score from SC A ,SC B where A.Score=B.Score and A.C# <>B.C# ;

43. 查询每门功成绩最好的前两名

SELECT t1.S# as 学生ID,t1.C# as 课程ID,Score as 分数 FROM SC t1 WHERE score IN (SELECT TOP 2 score FROM SC WHERE t1.C#= C# ORDER BY score DESC) ORDER BY t1.C#;

44. 统计每门课程的学生选修人数(超过10人的课程才统计)。要求输出课程号和选修

人数,查询结果按人数降序排列,查询结果按人数降序排列,若人数相同,按课程号升序排列

select C# as 课程号,count(*) as 人数 from sc group by C# order by count(*) desc,c#

45. 检索至少选修两门课程的学生学号

select S# from sc group by s# having count(*) > = 2 46. 查询全部学生都选修的课程的课程号和课程名

select C#,Cname from Course where C# in (select c# from sc group by c#)

47. 查询没学过“叶平”老师讲授的任一门课程的学生姓名

select Sname from Student where S# not in (select S# from Course,Teacher,SC where Course.T#=Teacher.T# and SC.C#=course.C# and Tname='叶平'); 48. 查询两门以上不及格课程的同学的学号及其平均成绩

select S#,avg(isnull(score,0)) from SC where S# in (select S# from SC where score <60 group by S# having count(*)>2)group by S#; 49. 检索“004”课程分数小于60,按分数降序排列的同学学号

select S# from SC where C#='004'and score <60 order by score desc; 50. 删除“002”同学的“001”课程的成绩

delete from Sc where S#='002'and C#='001';

四、 阿里巴巴Oracle DBA笔试题及参考答案 - 数据库基本概念类 (一) SQL tuning 类

1. 列举几种表连接方式

hash join/merge join/nest loop(cluster join)/index join 2. 不借助第三方工具,怎样查看sql的执行计划

set autot on

explain plan set statement_id = &item_id for &sql; select * from table(dbms_xplan.display);

--http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10752/ex_plan.htm

3. 如何使用CBO,CBO与RULE的区别

在optimizer_mode=choose时,如果表有统计信息(分区表外),优化器将选择CBO,否则选RBO。

RBO遵循简单的分级方法学,使用15种级别要点,当接收到查询,优化器将评估使用到的要点数目,然后选择最佳级别(最少的数量)的执行路径来运行查询。 CBO尝试找到最低成本的访问数据的方法,为了最大的吞吐量或最快的初始响应时间,计算使用不同的执行计划的成本,并选择成本最低的一个,关于表的数据内容的统计被用于确定执行计划。

4. 如何定位重要(消耗资源多)的SQL

select sql_text from v$sql where disk_reads > 1000 or (executions > 0 and buffer_gets/executions > 30000); 5. 如何跟踪某个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,''); 6. SQL调整最关注的是什么

查看该SQL的response time(db block gets/consistent gets/physicalreads/sorts (disk))

7. 说说你对索引的认识(索引的结构、对dml影响、为什么提高查询性能)

b-tree index/bitmap index/function index/patitional index(local/global)索引通常能提高select/update/delete的性能,会降低insert的速度。 8. 使用索引查询一定能提高查询的性能吗?为什么

索引就是为了提高查询性能而存在的,如果在查询中索引没有提高性能,只能说是用错了索引,或者讲是场合不同

9. 绑定变量是什么?绑定变量有什么优缺点?

绑定变量是相对文本变量来讲的,所谓文本变量是指在SQL直接书写查询条件,这样的SQL在不同条件下需要反复解析,绑定变量是指使用变量来代替直接书写条件,查询bind value在运行时传递,然后绑定执行。

优点是减少硬解析,降低CPU的争用,节省shared_pool 缺点是不能使用histogram,sql优化比较困难 10. 如何稳定(固定)执行计划

query_rewrite_enabled = true star_transformation_enabled = true optimizer_features_enable = 9.2.0 创建并使用stored outline

--(参考)

http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10752/outlines.htm#26854

这个贴子:

--(参考)http://www.cnoug.org/viewthread.php?tid=27598 11. 和排序相关的内存在8i和9i分别怎样调整,临时表空间的作用是什么

12. 8i中sort_area_size/sort_area_retained_size决定了排序所需要的内存如果排

序操作不能在sort_area_size中完成,就会用到temp表空间,9i中如果

workarea_size_policy=auto时,排序在pga内进行,通常pga_aggregate_target的1/20可以用来进行disk sort;

如果workarea_size_policy=manual时,排序需要的内存由sort_area_size决定, 在执行order by/group by/distinct/union/create index/index rebuild/minus等操作时,如果在pga或sort_area_size中不能完成,排序将在临时表空间进行(disk sort),临时表空间主要作用就是完成系统中的disk sort。

13. 存在表T(a,b,c,d),要根据字段c排序后取第21—30条记录显示,请给出sql

create table t(a number(8),b number(8),c number(8),d number(8)); begin

for i in 1 .. 300 loop

insert into t values(mod(i,2),i/2,dbms_random.value(1,300),i/4); end loop; end; /

select * from (select c.*,rownum as rn from (select * from t order by c desc) c) where rn between 21 and 30;

select * from (select * from test order by c desc) x where rownum < 30 minus

select * from (select * from test order by c desc) y where rownum < 20 order by 3 desc

相比之 minus性能较差

(二) 数据库基本概念类

1. pctused and pctfree 表示什么含义有什么作用

pctused与pctfree控制数据块是否出现在freelist中,pctfree控制数据块中保留用于update的空间,当数据块中的free space小于pctfree设置的空间时,该数据块从freelist中去掉,当块由于dml操作free space大于pct_used设置的空间时,该数据库块将被添加在freelist链表中。

2. 简单描述table / segment / extent / block之间的关系

table创建时,默认创建了一个data segment,每个data segment含有min extents指定的extents数,每个extent据据表空间的存储参数分配一定数量的blocks 3. 描述tablespace和datafile之间的关系

一个tablespace可以有一个或多个datafile,每个datafile只能在一个tablespace内, table中的数据,通过hash算法分布在tablespace中的各个datafile中, tablespace是逻辑上的概念,datafile则在物理上储存了数据库的种种对象。 4. 本地管理表空间和字典管理表空间的特点,ASSM有什么特点

本地管理表空间(Locally Managed Tablespace简称LMT),8i以后出现的一种新的表空间的管理模式,通过位图来管理表空间的空间使用。

字典管理表空间(Dictionary-Managed Tablespace简称DMT),8i以前包括以后都还可以使用的一种表空间管理模式,通过数据字典管理表空间的空间使用。

动段空间管理(ASSM),它首次出现在Oracle920里有了ASSM,链接列表freelist被位图所取代,它是一个二进制的数组,能够迅速有效地管理存储扩展和剩余区块(free block),因此能够改善分段存储本质,ASSM表空间上创建的段还有另外一个称呼叫Bitmap Managed Segments(BMB 段)。

搜索更多关于: Oracle面试题集锦 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

select count(*) from sc; 40. 查询选修“叶平”老师所授课程的学生中,成绩最高的学生姓名及其成绩 select Student.Sname,score from Student,SC,Course C,Teacher where Student.S#=SC.S# and SC.C#=C.C# and C.T#=Teacher.T# and Teacher.Tname='叶平' and SC.score=(select max(score)from SC where C#=C.C# ); 41. 查询各个课程及相应的选修人数 select count(*) from sc group by C#; 42. 查询不同课程成绩相同的学生的学号、课程号、学生成绩 select dist

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com