home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a524 / 37.ddi / demo / demo4.sql < prev    next >
Encoding:
Text File  |  1991-03-04  |  1.7 KB  |  48 lines

  1. rem
  2. rem $Header: demo4.sql,v 6.1 90/02/16 18:40:08 nsalah Exp $ demo4.sql Copyr (c) 1989 Oracle
  3. rem
  4. rem V6PLS10030,DISK$DEV2:[PLS1FREEZE.DEMO.10030]
  5. /*        SCRIPT: DEMO4                                          */
  6. /*      This PL/SQL procedure demonstrates PL/SQL loops and the        */
  7. /* efficiency increases that can be gained by using PL/SQL.            */
  8. /*      First, a PL/SQL Cursor FOR loop is used to loop through each   */
  9. /* row returned by a query.  This type of loop makes it simple to      */
  10. /* individually examine each row returned.                             */
  11. /*      Second, by processing each row, we are able to use only one    */
  12. /* SELECT statement to do the work of three SELECT statements.  This   */
  13. /* increases system efficiency.                                        */
  14.  
  15. set termout off
  16. START load_emp;
  17. delete from temp;
  18. commit;
  19. set termout on
  20.  
  21. prompt >>>>>  Here's the total wages of everyone in dept. 20:
  22. select sum(sal) + sum(nvl(comm,0)) total_wages from emp where deptno = 20;
  23.  
  24. prompt >>>>>  Here are the people in that department who have a salary
  25. prompt >>>>>  greater than $2000:
  26. select ename, sal from emp where sal > 2000 and deptno = 20;
  27.  
  28. prompt >>>>>  ... and those who have a commission larger than their salaries:
  29. select ename, comm, sal from emp where comm > sal and deptno = 20;
  30.  
  31. prompt >>>>>  Hit return to load our PL/SQL procedure to get the 
  32. prompt >>>>>  count information by issuing only ONE select statement...
  33. pause
  34.  
  35. GET demo4_pls
  36. .
  37.  
  38. prompt
  39. prompt >>>>>  Hit return to run our procedure...
  40. pause
  41. START demo4_pls
  42. /
  43.  
  44. prompt >>>>>  Now hit return to see all the information in the TEMP table...
  45. pause
  46.  
  47. select message total_wages, col1 high_sal, col2 higher_comm from temp;
  48.