home *** CD-ROM | disk | FTP | other *** search
- rem
- rem $Header: demo4.sql,v 6.1 90/02/16 18:40:08 nsalah Exp $ demo4.sql Copyr (c) 1989 Oracle
- rem
- rem V6PLS10030,DISK$DEV2:[PLS1FREEZE.DEMO.10030]
- /* SCRIPT: DEMO4 */
- /* This PL/SQL procedure demonstrates PL/SQL loops and the */
- /* efficiency increases that can be gained by using PL/SQL. */
- /* First, a PL/SQL Cursor FOR loop is used to loop through each */
- /* row returned by a query. This type of loop makes it simple to */
- /* individually examine each row returned. */
- /* Second, by processing each row, we are able to use only one */
- /* SELECT statement to do the work of three SELECT statements. This */
- /* increases system efficiency. */
-
- set termout off
- START load_emp;
- delete from temp;
- commit;
- set termout on
-
- prompt >>>>> Here's the total wages of everyone in dept. 20:
- select sum(sal) + sum(nvl(comm,0)) total_wages from emp where deptno = 20;
-
- prompt >>>>> Here are the people in that department who have a salary
- prompt >>>>> greater than $2000:
- select ename, sal from emp where sal > 2000 and deptno = 20;
-
- prompt >>>>> ... and those who have a commission larger than their salaries:
- select ename, comm, sal from emp where comm > sal and deptno = 20;
-
- prompt >>>>> Hit return to load our PL/SQL procedure to get the
- prompt >>>>> count information by issuing only ONE select statement...
- pause
-
- GET demo4_pls
- .
-
- prompt
- prompt >>>>> Hit return to run our procedure...
- pause
- START demo4_pls
- /
-
- prompt >>>>> Now hit return to see all the information in the TEMP table...
- pause
-
- select message total_wages, col1 high_sal, col2 higher_comm from temp;
-