文章标题

来源:互联网 发布:电脑办公软件自学 编辑:程序博客网 时间:2024/06/01 10:25

题目
Through the below execise, you can create the block,procedure,exeception.
–PL/SQL
2. Create a procedure called MY_PROCEDURE to output the phrase “My Procedure Works” to the screen.Then rewrite it in a function
3. Create a procedure to modify the salary to a 10% araise in EMP for a given empno.
4. Create and execute a procedure named MULTIPLIER that accepts two numbers through variables. The first number should be
divided by the second number and have the second number added to the result. The result should be written to a
PL/SQL variable and printed to the screen.Then rewite it in a function
5. Create a procedure to insert a new department into the DEPT table.
a. Use the DEPT_ID sequence generator for the department number.
b. Create a parameter for the department name.
c. Create a parameter for the location.
d. Execute the procedure.
6. Create a procedure to update the location for the department you created in execrise 5.
a. Create a parameter for the department number.
b. Create a parameter for the location number.
d. Test the procedure. What happens if you enter a location number that does not exist?
7. Create a procedure named EMP_MESSAGE that selects the employee last name,start date, and salary based on an employee number
provided at execution. Print a message to the screen based on any combination of one of the following criteria.
Criteria Message
Salary greater than 1200 Salary more than 1200
Name contains “R” Name contains “R”
Start date is in March March start date
None of the above None
8. Create a procedure ADD_COMMENTS to add a new columns in EMP
a. Add a new column named COMMENTS ;
b. According to the following criteria,update COMMENTS :
Criteria Comments
Have subordinate Is a manager
Have no subordinate is a clerk
c. Execuite the procedure
9. Write a procedure named SALARY_RANGE that prints the names of the employees that make plus or minus $100 of the salary value entered.

a. If there is no employee within that salary range, then print a message to the user indicating that is the case. Use an exception for this case.
b. If there are more than 3 employees within that range, then the message should indicate how many employees have that salary range.
Your results should look like the list below:
PL/SQL> SALARY_RANGE (1000);
Employees who make around 1000are:Biri,Schwartz,SmithPL/SQL>SALARYRANGE(900);4employeesalariesarewithin100 of 900PL/SQL>SALARYRANGE(2000);Exception:Norecordswithinthe2000 range.
10. Create a procedure EXCEPTION_DESIGN which use the predefined and user definded exception:
a. Create a parameter for empno ;
b. if the employee work over 5 years,the salary will increase 2000.Over 3 years, the salary will increate 1000, less than 3 years,
add the user exception to output the message: The employee is out the range of adding salary.
答案:
第二题:
create or replace procedure cux_practice_one is
begin
fnd_file.put_line(apps.fnd_file.output, ‘My Procedure Works’);
end cux_practice_one;
第三题:
create or replace procedure cux_procedure is

begin
update emp set sal=sal*1.1 where emp.empno =’7369’;
– dbms_output.put_line (fun_count(‘7369’));
end cux_procedure;
第四题:
declare
v_dividend float;
v_divisor float;
v_result float;

begin
v_dividend:=&被除数;
v_divisor:=&除数;
v_result:=v_dividend/ v_divisor;

  dbms_output.put_line(v_result ||'和'|| v_divisor);  end; 

第五题:
create or replace procedure cux_create_dept
(deptno in number,dname in varchar2,loc in varchar2)
is
begin
insert into dept values(deptno,dname,loc);

end cux_create_dept;
第六题:
–根据deptno 来更新
update dept set loc=’beijing’ where dept.deptno=20
–由于表中没有location number这个字段,所以我就向表中添加进入该字段,并加入相应的数据。
alter table dept add locnu varchar(20);
update dept set locnu=’101’ where dept.deptno=10;
update dept set locnu=’102’ where dept.deptno=20;
update dept set locnu=’103’ where dept.deptno=30;
update dept set locnu=’104’ where dept.deptno=40;
–根据location number 来更新
update dept set loc=’shanghai’ where dept.locnu=’102’;
–如果写一个不存在的location number 来进行更新的话,该程序不会报错,并且进行编译,显示0行被更新。
update dept set loc=’us’ where dept.locnu=’108’;
第七题:
create or replace procedure cux_create_dept
(deptno in number,dname in varchar2,loc in varchar2)
is
begin
insert into dept values(deptno,dname,loc);

end cux_create_dept;

第八题:
/*declare
b_empno emp%rowtype;
p_no number(4);
empno number(4);
ename varchar2(10);
hiredate date ;

cursor v_empno is
select emp.ename,emp.hiredate,emp.sal,emp.empno from emp where emp.sal>1200;
begin
for b_empno in v_empno
loop
dbms_output.put_line(b_empno.empno||’-‘||b_empno.ename||’-‘||b_empno.hiredate||’—’||b_empno.sal);
end loop;
end;*/
/* declare
b_empno emp%rowtype;
p_no number(4);
empno number(4);
ename varchar2(10);
hiredate date ;

cursor v_empno is
select emp.ename,emp.hiredate,emp.sal,emp.empno from emp where emp.ename like ‘%R%’;
begin
for b_empno in v_empno
loop
dbms_output.put_line(b_empno.empno||’-‘||b_empno.ename||’-‘||b_empno.hiredate||’—’||b_empno.sal);
end loop;
end;*/
declare
b_empno emp%rowtype;
p_no number(4);
empno number(4);
ename varchar2(10);
hiredate date;

cursor v_empno is
select emp.ename,
emp.hiredate,
emp.sal,
emp.empno
from emp
where emp.hiredate(month,[dateadd],getdate())=3;
begin
for b_empno in v_empno loop
dbms_output.put_line(b_empno.empno || ‘-’ || b_empno.ename || ‘-’ ||
b_empno.hiredate || ‘—’ || b_empno.sal);
end loop;
end;
第八题:
alter table emp add COMMENTS varchar(20);
update emp set comments =’Have subordinate’ where job=’MANAGER’;
update emp set comments =’Have NO subordinate’ where job=’CLERK’;
update emp set comments =” where job<>’MANAGER’and job<>’CLERK’;
select comments from emp ;
select * from emp;
end ;
第十题:
declare
e_toosmallsalary exception;
hiredate date;
hd date;
sal number;
cursor v_auth is
select emp.hiredate from emp ;

begin

for v_buth in v_auth
loop
if sysdate-v_buth.hiredate>5 then
update emp set emp.sal=emp.sal+2000;
end if;
if sysdate-v_buth.hiredate>3 and sysdate-v_buth.hiredate< 5 then
update emp set emp.sal=emp.sal+1000;
end if ;
if sysdate-v_buth.hiredate<3 then
raise e_toosmallsalary;
dbms_output.put_line(‘The employee is out the range of adding salary’);
end if ;
end loop;
end;

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 3个月的宝宝认人怎么办 十天大的婴儿大便是泡沫该怎么办 婴儿3天没有拉大便了怎么办 儿童两三天拉一次大便是稀便怎么办 五个月的婴儿一星期没大便怎么办 宝宝53天几天没大便了怎么办 42天宝宝4天没有大便怎么办 42天的宝宝3天没大便怎么办 6个月宝宝前额头碰青了怎么办 三个月的婴儿喝牛奶拉绿大便怎么办 已经喂了猫一个多月的高钙奶怎么办 几个月宝宝胳膊起来红豆豆怎么办 一岁半宝宝只喝牛奶不吃饭怎么办 儿子一生下来脖子上有淋巴结怎么办 满月宝宝睡觉不踏实易惊醒怎么办 两个月宝宝从婴儿车上掉下来怎么办 兔子不吃兔粮不喝水不拉粑粑怎么办 兔子吃了带水的菜叶怎么办 七个月的宝宝晚上睡觉总醒怎么办 紫薯和番茄一起吃了怎么办 1当半宝宝喝温开水后打隔怎么办 婴儿屁股拉便便肛门有点烂了怎么办 婴儿便便之后肛门就红怎么办 50天的宝宝三天不拉大便怎么办 两个月宝宝不拉屎只放屁怎么办 两个月大宝宝两天没拉屎怎么办 两个月宝宝三天没拉大便怎么办 5个月宝宝3天没拉大便怎么办 4个月宝宝3天没拉大便怎么办 20个月的宝宝大便干燥怎么办 20个月宝宝大便间隔三天怎么办 两个多月的宝宝四天没大便怎么办 两个多月的宝宝几天没大便怎么办 2个月3天没大便怎么办 两个月大的宝宝发烧40度怎么办 两个月大的宝宝感冒了怎么办 四个月宝宝拉水样大便要怎么办 六个月的宝宝咳嗽有痰怎么办 未满月的宝宝大便脓状怎么办 五个月的宝宝总是吃手怎么办 小孩子学数字怎么也学不会怎么办