Please note that all the examples in this series have been tested only with Oracle 10g. I didn’t really test them with all the previous versions of Oracle. I suggest you to refer the documentation of respective version you are using, if any of the programs failed to execute. More about FUNCTION My previous article actually stopped at a simple example on FUNCTION. Now we shall extend its limit. Consider the following example: declare CURSOR c_emp is select ename,deptno from emp; function getDname(p_deptno dept.deptno%type) return varchar2 is v_dname dept.dname%type; begin select dname into v_dname from dept where deptno = p_deptno;
return v_dname; end; begin for r_emp in c_emp loop dbms_output.put_line(r_emp.ename || ',' || getDname(r_emp.deptno)); end loop; end; The above program really makes use of FUNCTION properly. We are sending ‘deptno’ as a parameter to the function ‘getDname’ which returns the department name back to the main program. Actually we can store the value returned back by ‘getDname’ (demonstrated in part 13), but it would be easy to write directly within the DBMS_OUTPUT statement in the main program as above.
blog comments powered by Disqus |
|
|
|
|
|
|
|