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

上传人:b****9 文档编号:26143279 上传时间:2023-06-17 格式:DOCX 页数:9 大小:16.36KB
下载 相关 举报
一道Oracle笔试题 附网友答案.docx_第1页
第1页 / 共9页
一道Oracle笔试题 附网友答案.docx_第2页
第2页 / 共9页
一道Oracle笔试题 附网友答案.docx_第3页
第3页 / 共9页
一道Oracle笔试题 附网友答案.docx_第4页
第4页 / 共9页
一道Oracle笔试题 附网友答案.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

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

《一道Oracle笔试题 附网友答案.docx》由会员分享,可在线阅读,更多相关《一道Oracle笔试题 附网友答案.docx(9页珍藏版)》请在冰豆网上搜索。

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

一道Oracle笔试题附网友答案

一道Oracle笔试题附网友答案

问题:

一道Oracle笔试题附网友答案回答:

考试总分为100分,共8题,时间为1小时。

表结构说明:

createtableemployee(

idnumber(10)notnull,员工工号

salarynumber(10,2)default0notnull,薪水

namevarchar2(24)notnull姓名

);

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>createtableemployee(

2idnumber(10)notnull,员工工号

3salarynumber(10,2)default0notnull,薪水

4namevarchar2(24)notnull姓名

5);

表已创建。

第一题答案:

SQL>Createsequenceseq_employeeincrementby1startwith1nomaxvaluenocycle;

序列已创建。

第二题答案:

SQL>declareinumber;

2begin

3foriin1..100

4loop

5insertintoemployee

6values(seq_employee.nextval,1950+i,王明||to_char(i));

7commit;

8endloop;

9end;

10/

PL/SQL过程已成功完成。

SQL>select*fromemployeewhererownum

IDSALARYNAME

--

11951王明1

21952王明2

31953王明3

41954王明4

51955王明5

61956王明6

71957王明7

81958王明8

91959王明9

101960王明10

已选择10行。

3.写一个语句块,在语句块中定义一个显式游标,按id升序排列,打印表employee中前十条数据。

(15分)

-第三题答案:

SQL>declare

2cursorcisselectid,salary,namefrom(select*fromemployeeorderbyid)whererownum

3v_recordc%rowtype;

4begin

5openc;

6loop

7fetchcintov_record;

8exitwhenc%notfound;

9dbms_output.put_line(to_char(v_record.id)||,||to_char(v_record.salary)||,||v_record.name);

10endloop;

11closec;

12end;

13/

1,1951,王明1

2,1952,王明2

3,1953,王明3

4,1954,王明4

5,1955,王明5

6,1956,王明6

7,1957,王明7

8,1958,王明8

9,1959,王明9

10,1960,王明10

PL/SQL过程已成功完成。

4.创建存储过程p_employee,输入员工薪水范围,返回员工工号、姓名、薪水结果集,结果集按员工薪水升序排列。

(15分)

-第四题答案

SQL>createorreplaceprocedurep_employee

2(iminsalaryinnumber,

3imaxsalaryinnumber)

4is

5begin

6forxin(selectid,salary,namefrom(select*fromemployeewheresalarybetweeniminsalaryandimaxsalary)orderbysalary)

7loop

8dbms_output.put_line(to_char(x.id)||to_char(x.salary)||x.name);

9endloop;

10end;

11/

过程已创建。

SQL>execp_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>createorreplacefunctionf_employeereturnnumber

is

begin

updateemployeesetsalary=salary+salary*0.05wheresalary

commit;

ifsql%rowcount=0then

return1;

else

return0;

endif;

end;

/

函数已创建。

第六题答案

SQL>declareanumber;

2begin

3a:

=f_employee();

4dbms_output.put_line(to_char(a));

5end;

6/

0

PL/SQL过程已成功完成。

SQL>select*fromemployeewheresalary

未选定行

SQL>select*fromemployeewhererownum

IDSALARYNAME

--

12048.55王明1

22049.6王明2

32050.65王明3

42051.7王明4

52052.75王明5

62053.8王明6

72054.85王明7

82055.9王明8

92056.95王明9

102058王明10

112059.05王明11

IDSALARYNAME

--

122060.1王明12

132061.15王明13

142062.2王明14

152063.25王明15

162064.3王明16

172065.35王明17

182066.4王明18

192067.45王明19

202068.5王明20

212069.55王明21

222070.6王明22

IDSALARYNAME

--

232071.65王明23

242072.7王明24

252073.75王明25

262074.8王明26

272075.85王明27

282076.9王明28

292077.95王明29

302079王明30

312080.05王明31

322081.1王明32

332082.15王明33

IDSALARYNAME

--

342083.2王明34

352084.25王明35

362085.3王明36

372086.35王明37

382087.4王明38

392088.45王明39

402089.5王明40

412090.55王明41

422091.6王明42

432092.65王明43

442093.7王明44

IDSALARYNAME

--

452094.75王明45

462095.8王明46

472096.85王明47

482097.9王明48

492098.95王明49

已选择49行。

第七题答案

SQL>createorreplaceprocedurep_create_emp

2is

3v_countnumber;

4begin

5selectcount(*)intov_countfromuser_tableswheretable_name=EMPLOYEE

6ifv_count=0then

7return;

8else

9executeimmediatedroptableemployee

10endif;

11end;

12/

过程已创建。

第八题答案

SQL>execp_create_emp;

PL/SQL过程已成功完成。

SQL>select*fromemployee;

select*fromemployee

*

ERROR位于第1行:

ORA-00942:

表或视图不存在

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1