sun_sal out number) is begin
select 12*(sal+nvl(comm,0)) into sun_sal from emp
where deptno=v_deptno; exception
when no_data_found then sun_sal:='0'; end;
5、写一个pl/sql程序块:根据scott模式下的emp表和dept表,输出每个部门的编号和部门名称,以及该部门下所有的雇员和雇员工资,及其该部门的总人数。 输出效果如下:
部门编号:-- 部门名称:-- 雇员姓名:-- 雇员工资:-- 该部门总人数:--
declare
CURSOR c_dept IS SELECT deptno,dname FROM dept ORDER BY
deptno;
CURSOR c_emp (p_dept VarCHAR2) IS
SELECT ename,sal FROM emp WHERE deptno=p_dept ORDER BY ename; n number; BEGIN
FOR r_dept IN c_dept LOOP
DBMS_OUTPUT.PUT_LINE('部门编号:'|| r_dept.deptno||'--部门名 称:'||r_dept.dname); n:=0;
FOR r_emp IN c_emp(r_dept.deptno) LOOP
DBMS_OUTPUT.PUT_LINE('雇员姓名: '||r_emp.ename || ' 雇员工资:'||r_emp.sal); n:=n+1; END LOOP;
DBMS_OUTPUT.PUT_LINE(r_dept.dname||'部门的总人数:'|| n); END LOOP; END;
6.创建一个语句级触发器CHECK_TIME,限定对表EMP的修改时间为周一至周五的早8点至晚5点。
create or replace trigger CHECK_TIME before update or insert or delete on emp begin
if (to_char(sysdate,'DY') in ('sat','sun')) or to_char(sysdate,'HH24')<'08' or to_char(sysdate,'HH24')>='17' then
raise_application_error(-20500,'只能在工作时间对表操作!'); end if; end;