欢迎来到天天文库
浏览记录
ID:55550741
大小:758.00 KB
页数:9页
时间:2020-05-16
《oracle-上机考试试题与答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1、写一个pl/sql程序块:直接使用数据类型定义两个变量v_empno和v_ename,从scott模式下的emp表中检索某个员工的编号empno和姓名ename,存储到v_empno和v_ename,并输出此员工的编号和姓名。setserveroutputondeclaretypemerchandiseisrecord(v_empnonumber(30),v_enamevarchar2(30));record_merchandisemerchandise;beginselectempno,enameintorecord_merchandisefromemp
2、whereempno='7369';dbms_output.put_line(record_merchandise.v_empno);dbms_output.put_line(record_merchandise.v_ename);end;2、写一个pl/sql程序块:根据scott模式下的emp表中的部门编号deptno字段的值,为姓名为SCOTT的雇员修改工资;若他所在部门号为10,则工资加100;若部门号为20,则工资加300;否则工资加400。setserveroutputondeclarev_deptnoemp.deptno%type;addsale
3、mp.sal%type;salnumber;beginselectdeptnointov_deptnofromempwhereename='SCOTT';ifv_deptno='10'thenaddsal:=100;elsifv_deptno='20'thenaddsal:=300;elseaddsal:=400;endif;updateempsetsal=sal+addsalwhereename='SCOTT';dbms_output.put_line(sal);end;3、写一个pl/sql程序块:定义一个游标类型type_cursor,然后使用type_
4、cursor定义变量ref_cur;根据scott模式下的emp表和dept表,使用游标变量ref_cur检索员工姓名和工作信息,并输出员工姓名和工作信息;使用游标变量ref_cur检索部门编号和部门名称信息,并输出部门编号和部门名称信息。setserveroutputondeclaretypetype_cursorisrefcursor;ref_curtype_cursor;mer_recemp%rowtype;ner_recdept%rowtype;beginopenref_curforselectename,jobfromemp;loopfetchref
5、_curintomer_rec;exitwhenref_cur%notfound;dbms_output.put(mer_rec.ename
6、
7、'');dbms_output.put(mer_rec.job);endloop;openref_curforselectdeptno,dnamefromdept;loopfetchref_curintoner_rec;exitwhenref_cur%notfound;dbms_output.put(ner_rec.deptno
8、
9、'');dbms_output.put(ner_rec.dname);endloop;c
10、loseref_cur;end;4、写一个pl/sql存储过程:根据scott模式下的emp表,写一个带参数的存储过程proc(deptnoinnumber,sun_saloutnumber),输入部门编号,输出该部门的总工资信息。并写一个pl/sql程序块,测试该存储过程。createorreplaceproceduresearchmerch(v_deptnoinnumber,sun_saloutnumber)isbeginselect12*(sal+nvl(comm,0))intosun_salfromempwheredeptno=v_deptno;exc
11、eptionwhenno_data_foundthensun_sal:='0';end;5、写一个pl/sql程序块:根据scott模式下的emp表和dept表,输出每个部门的编号和部门名称,以及该部门下所有的雇员和雇员工资,及其该部门的总人数。输出效果如下:部门编号:--部门名称:--雇员姓名:--雇员工资:--该部门总人数:--declareCURSORc_deptISSELECTdeptno,dnameFROMdeptORDERBYdeptno;CURSORc_emp(p_deptVarCHAR2)ISSELECTename,salFROMempWHER
12、Edeptno=p_deptORDER
此文档下载收益归作者所有