Oracle作业题
一.创建一个简单的PL/SQL程序块
使用不同的程序块组件工作
使用编程结构编写PL/SQL程序块
处理PL/SQL程序块中的错误
1.编写一个程序块,从emp表中显示名为“SMITH”的雇员的薪水和职位。
declare
v_emp emp%rowtype;
begin
select*into v_emp from emp where ename='SMITH';
dbms_output.put_line('员工的工作是:'||v_emp.job||';他的薪水是:
'||v_emp.sal);
end;
2.编写一个程序块,接受用户输入一个部门号,从dept表中显示该部门的名称与所在位置。方法一:(传统方法)
declare
v_loc deptcp.dname%type;
v_dname deptcp.dname%type;
v_deptno deptcp.deptno%type;
begin
v_deptno:=&部门编号;
select loc,dname into v_loc,v_dname from deptcp where deptno=v_deptno; dbms_output.put_line('员工所在地是:'||v_loc||';部门名称是:'||v_dname); exception
when no_data_found
then dbms_output.put_line('您输入的部门编号不存在,请从新输入,谢谢'); end;
方法二:(使用%rowtype)
declare
v_dept dept%rowtype;
begin
select*into v_dept from dept where deptno=&部门号;
dbms_output.put_line(v_dept.dname||'--'||v_dept.loc);
end;
3.编写一个程序块,利用%type属性,接受一个雇员号,从emp表中显示该雇员的整体薪水(即,薪水加佣金)。(*期末考试试题*)
declare
v_sal emp.sal%type;
begin
select sal+comm into v_sal from emp where empno=&雇员号;