Oracle面试问题_第1页
Oracle面试问题_第2页
Oracle面试问题_第3页
Oracle面试问题_第4页
Oracle面试问题_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Q1.影响oracle查询性能的因素都有哪些?1. 硬件配置:处理器速度,内存大小,磁盘读写速度,网络传输速度等等,这些都影响oracle 的整体性能和查询性能2. 是否建立了索引,索引是否合理3. 表碎片和索引碎片,生产库由于长时间运营,碎片可能导致查询使用错误的执行计划,导致查询速度变慢4. 表或者索引的initial 参数配置不同,导致数据扩展区大小不一,也可能导致查询速度降低。5. SQL执行效率低下,导致查询速度很慢6. 数据库负载过大Q2.考试总分为100分,共8题,时间为1小时。表结构说明:create table employee(id number(10 not null,

2、员工工号salary number(10,2 default 0 not null, 薪水name varchar2(24 not null 姓名;1.创建序列seq_employee,该序列每次取的时候它会自动增加,从1开始计数,不设最大值,并且一直累加,不循环。(10分2.写一个PL/SQL块,插入表user.employee中100条数据。插入该表中字段id用序列seq_employee实现,薪水和姓名字段可以任意填写。(15分6.写一个匿名语句块,用于执行函数f_employee,并打印执行该函数的结果。(8分7.创建存储过程p_create_emp,用于判断表employee是否存在

3、,如果存在则删除该表。(15分8.写一个匿名语句块,用于执行存储过程p_create_emp。(7分答案如下:SQL> create table employee(2 id number(10 not null, 员工工号3 salary number(10,2 default 0 not null, 薪水4 name varchar2(24 not null 姓名5 ;表已创建。第一题答案:SQL> Create sequence seq_employee increment by 1 start with 1 nomaxvalue nocycle;序列已创建。第二题答案:SQL

4、> declare i number;2 begin3 for i in 1 . 1004 loop5 insert into employee6 values(seq_employee.nextval,1950+i,王明|to_char(i;7 commit;8 end loop;9 end;10 /PL/SQL 过程已成功完成。SQL> select * from employee where rownum<11;ID SALARY NAME- - 1 1951 王明12 1952 王明23 1953 王明34 1954 王明45 1955 王明56 1956 王明67

5、1957 王明78 1958 王明89 1959 王明910 1960 王明10已选择10行。3.写一个语句块,在语句块中定义一个显式游标,按id升序排列,打印表employee中前十条数据。(15分-第三题答案:SQL> declare2 cursor c is select id,salary,name from(select * from employee order by id where rownum<11;3 v_record c%rowtype;4 begin5 open c;6 loop7 fetch c into v_record;8 exit when c%no

6、tfound;9 dbms_output.put_line(to_char(v_record.id|,'|to_char(v_record.salary|,'|v_;10 end loop;11 close c;12 end;13 /1,1951,王明12,1952,王明23,1953,王明34,1954,王明45,1955,王明56,1956,王明67,1957,王明78,1958,王明89,1959,王明910,1960,王明10PL/SQL 过程已成功完成。4.创建存储过程p_employee,输入员工薪水范围,返回员工工号、姓名、薪水结果集,结果集

7、按员工薪水升序排列。(15分-第四题答案SQL> create or replace procedure p_employee2 (iminsalary in number,3 imaxsalary in number4 is5 begin6 for x in(select id,salary,name from(select * from employee where salary between iminsalary and imaxsalary order by salary7 loop8 dbms_output.put_line(to_char(x.id|to_char(x.sa

8、lary|;9 end loop;10 end;11 /过程已创建。SQL> exec p_employee(2000,2007;502000王明50512001王明51522002王明52532003王明53542004王明54552005王明55562006王明56572007王明57PL/SQL 过程已成功完成。5.创建函数f_employee实现更新员工薪水的功能,将薪水低于2000且姓wang的员工薪水加5%,其他不变,更新成功则返回0,否则返回1。(15分第五题答案SQL> create or replace function f_employee retu

9、rn numberisbeginupdate employee set salary=salary+salary*0.05 where salary<2000 and name like 王%; commit;if sql%rowcount=0 thenreturn 1;elsereturn 0;end if;end;/函数已创建。第六题答案SQL> declare a number;2 begin3 a:=f_employee(;4 dbms_output.put_line(to_char(a;5 end;6 /PL/SQL 过程已成功完成。SQL> select * fr

10、om employee where salary<2000 and name like 王%; 未选定行SQL> select * from employee where rownum<50;ID SALARY NAME- - 1 2048.55 王明12 2049.6 王明23 2050.65 王明34 2051.7 王明45 2052.75 王明56 2053.8 王明67 2054.85 王明78 2055.9 王明89 2056.95 王明910 2058 王明1011 2059.05 王明11ID SALARY NAME- - 12 2060.1 王明1213 20

11、61.15 王明1314 2062.2 王明1415 2063.25 王明1516 2064.3 王明1617 2065.35 王明1718 2066.4 王明1819 2067.45 王明1920 2068.5 王明2021 2069.55 王明2122 2070.6 王明22ID SALARY NAME- - 23 2071.65 王明2324 2072.7 王明2425 2073.75 王明2526 2074.8 王明2627 2075.85 王明2728 2076.9 王明2829 2077.95 王明2930 2079 王明3031 2080.05 王明3132 2081.1 王明3

12、233 2082.15 王明33ID SALARY NAME- - 34 2083.2 王明3435 2084.25 王明3536 2085.3 王明3637 2086.35 王明3738 2087.4 王明3839 2088.45 王明3940 2089.5 王明4041 2090.55 王明4142 2091.6 王明4243 2092.65 王明4344 2093.7 王明44ID SALARY NAME- - 45 2094.75 王明4546 2095.8 王明4647 2096.85 王明4748 2097.9 王明4849 2098.95 王明49已选择49行。第七题答案SQL&

13、gt; create or replace procedure p_create_emp2 is3 v_count number;4 begin5 select count(* into v_count from user_tables where table_name=EMPLOYEE;6 if v_count=0 then7 return;8 else9 execute immediate drop table employee; 10 end if; 11 end; 12 / 过程已创建。 第八题答案 SQL> exec p_create_emp; PL/SQL 过程已成功完成。

14、SQL> select * from employee; select * from employee * ERROR 位于第 1 行: ORA-00942: 表或视图不存在 Q3. Oracle 如何改变 listener 的端口号 (Linux 服务器 可以参照如下步骤改变 listener 的端口号: 1. 使用命令 lsnrctl stop 停止 listener 的执行 2. 用 lsnrctl status 命令确认 listener 已经停止以后, 到$ORACLE_HOME/network/admin 下找 到 listener.ora 这个文件。 3. 用 vi 或其他

15、编辑器打开这个文件, 将里面 listener 的端口号修改成你想要的值, 这里是由 1522 改成 1521。 4. 保存修改好的文件 5. 启动 sqlplus 以 SYSTEM 账户登录数据库,sqlplus SYSTEM/yourpasslocalhost 6. 在 sqlplus 里面执行如下命令: ALTER SYSTEM SET LOCAL_LISTENER "(ADDRESS=(PROTOCOL=TCP(HOST=oraclehost(PORT=1521" ALTER SYSTEM REGISTER; 7. 执行 lsnrctl status 验证 list

16、ener 状态。 如果 listener 状态正常,这端口号就修改成功了,也可以用 netstat -an | grep 15 来判断一下 Q4. Given an int array of size billions.Print the 100 max elements from the array in O(n.You are allowed to modify the array if u want to. The solution lies in finding the nth element largest element from a sequence of number. Thi

17、s can be done using the famous SELECT algorithm which lets us find the nth largest element from a = series of number. This work in O(n(/wiki/Selection_algorithm. Try to find (N-100 element. The end result will give us 2 sets. Chose the one where all the elements are greater tha

18、n the (N-100th element. I will not specify the complete working here. You may want to read here /wiki/Selection_algorithm Q5. Write a Java program that prints the size of a non-primitive Java object. 28 down vote accepted You can use the java.lang.instrumentation package: Compi

19、le and put this class in a JAR: import java.lang.instrument.Instrumentation; public class ObjectSizeFetcher private static Instrumentation instrumentation; public static void premain(String args, Instrumentation inst instrumentation = inst; public static long getObjectSize(Object o return instrumentation

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论