DBA面试题

当前位置: 面试问题网 > DBA面试题 > 一道Oracle笔试题附网友答案

一道Oracle笔试题附网友答案

考试总分为100分,共8题,时间为1小时。
   表结构说明:
   create table employee(
   id number(10) not null, — 员工工号
   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是否存在,如果存在则删除该表。(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> declare i number;
   2 begin
   3 for i in 1 .. 100
   4 loop
   5 insert into employee
   6 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 declare
   2 cursor c is select id,salary,name from(select * from employee order by id) where rownum create or replace procedure p_employee
   2 (iminsalary in number,
   3 imaxsalary in number)
   4 is
   5 begin
   6 for x in(select id,salary,name from(select * from employee where salary between iminsalary and imaxsalary) order by salary)
   7 loop
   8 dbms_output.put_line(to_char(x.id)||to_char(x.salary)||x.name);
   9 end loop;
   10 end;
   11 /
   过程已创建。
   SQL> exec p_employee(2000,2007);
   502000王明50
   512001王明51
   522002王明52
   532003王明53
   542004王明54
   552005王明55
   562006王明56
   572007王明57
   PL/SQL 过程已成功完成。
   5.创建函数f_employee实现更新员工薪水的功能,将薪水低于2000且姓wang的员工薪水加5%,其他不变,更新成功则返回0,否则返回1。(15分)
   ———第五题答案
   SQL> create or replace function f_employee return number
   is
   begin
   update employee set salary=salary+salary*0.05 where salary declare a number;
   2 begin
   3 a:=f_employee();
   4 dbms_output.put_line(to_char(a));
   5 end;
   6 /
   0
   PL/SQL 过程已成功完成。
   SQL> select * from employee where salary select * from employee where rownum create or replace procedure p_create_emp
   2 is
   3 v_count number;
   4 begin
   5 select count(*) into v_count from user_tables where table_name=’EMPLOYEE’;
   6 if v_count=0 then
   7 return;
   8 else
   9 execute immediate ‘drop table employee’;
   10 end if;
   11 end;
   12 /
   过程已创建。
  
   ———第八题答案
   SQL> exec p_create_emp;
   PL/SQL 过程已成功完成。
   SQL> select * from employee;
   select * from employee
   *
   ERROR 位于第 1 行:
   ORA-00942: 表或视图不存在

【一道Oracle笔试题附网友答案】相关文章

1. 一道Oracle笔试题附网友答案

2. 一套带网友答案的.NET笔试题

3. 一道oracle面试题

4. 几道Oracle面试题值得一看

5. 网络管理员笔试题面试题附带参考答案

6. 一套Oracle面试题笔试题及参考答案

7. 通用C#笔试题附答案

8. C和C++经典笔试题附答案解析

9. 阿里巴巴的Oracle DBA笔试题答案-SQL tuning类

10. 阿里巴巴Oracle DBA笔试题答案-备份恢复类

本文来源:https://www.mianshiwenti.com/a13407.html

点击展开全部

《一道Oracle笔试题附网友答案》

将本文的Word文档下载到电脑,方便收藏和打印

推荐程度:

进入下载页面

﹝一道Oracle笔试题附网友答案﹞相关内容

「一道Oracle笔试题附网友答案」相关专题

其它栏目

也许您还喜欢