pl/sql中特殊的null 过程如下: create or replace procedure zjx_pro_mgr(managerid in emp.mgr%type) is type zjx_emp_cursor is ref cursor; test_cursor zjx_emp_cursor; v_empno emp.empno%type; v_ename emp.ename%type; v_job emp.job%type; v_mgr emp.mgr%type; v_hiredate emp.hiredate%type; v_sal emp.sal%type; v_comm emp.comm%type; v_deptno emp.deptno%type; --type zjx_table_type is table of emp.mgr%type index by binary_integer; --zjx_mgr zjx_table_type; begin select distinct emp.mgr into v_mgr from emp where emp.mgr=managerid; if v_mgr is not null then open test_cursor for select * --select emp.empno,emp.ename,emp.job,emp.mgr,emp.hiredate,emp.sal,emp.comm,emp.deptno from emp where emp.mgr=v_mgr; loop fetch test_cursor into v_empno,v_ename,v_job,v_mgr,v_hiredate,v_sal,v_comm,v_deptno; exit when test_cursor%notfound; dbms_output.put_line(v_empno||v_ename||v_job||v_mgr||v_hiredate||v_sal||v_comm||v_deptno); end loop; else dbms_output.put_line(managerid||'不是一个manager'); end if; end; 如果红色字体字段返回值是空,则报错:如下: ORA-01403: 未找到任何数据 ORA-06512: 在 "SCOTT.ZJX_PRO_MGR", line 15 ORA-06512: 在 line 2 可能原因分析:可以赋空值给变量,但是select distinct emp.mgr into v_mgr from emp where emp.mgr=managerid;之后返回的实际是一个空表,不能直接赋给变量。 处理方法:红色字段作如下处理即可,max函数可以随意更换,只要能返回空值null即可。 create or replace procedure zjx_pro_mgr(managerid in emp.mgr%type) is type zjx_emp_cursor is ref cursor; test_cursor zjx_emp_cursor; v_empno emp.empno%type; v_ename emp.ename%type; v_job emp.job%type; v_mgr emp.mgr%type; v_hiredate emp.hiredate%type; v_sal emp.sal%type; v_comm emp.comm%type; v_deptno emp.deptno%type; --type zjx_table_type is table of emp.mgr%type index by binary_integer; --zjx_mgr zjx_table_type; begin select distinct max(emp.mgr) into v_mgr from emp where emp.mgr=managerid; if v_mgr is not null then open test_cursor for select * --select emp.empno,emp.ename,emp.job,emp.mgr,emp.hiredate,emp.sal,emp.comm,emp.deptno from emp where emp.mgr=v_mgr; loop fetch test_cursor into v_empno,v_ename,v_job,v_mgr,v_hiredate,v_sal,v_comm,v_deptno; exit when test_cursor%notfound; dbms_output.put_line(v_empno||v_ename||v_job||v_mgr||v_hiredate||v_sal||v_comm||v_deptno); end loop; else dbms_output.put_line(managerid||'不是一个manager'); end if; end; 注:所有的组函数都可以处理 空表,空字段等空,而单行处理函数只能处理空值null,不能处理空表或空字段等; 空值null和空有很大的区别。
|
|
来自: 昵称30748390 > 《软件测试》