iSelfSchooling.com - Copyright © 1999-2007 iSelfSchooling.com  References  Job Openings  |  Secure Login
    Home  | Search more...  |  FREE Online VIDEO Oracle Training  |  Gift Store  |  Bookstore

   Unlimited access!   

    Oracle  Syntax  | Suggestions Your Contribution  |  FREE Legal Forms

 

Email2aFriend Homepage us! |  Bookmark   -  Copyright & User Agreement

Products/Services

 Vision/Mission

 Community Sharing

 Services

  Products

 Biography

 Contact Us

 FAQ

 Current News

 Website Traffic

 Bookstore

 FREE Training

 SQL

 PL/SQL

 Forms 

 Reports

 Other TOOLS

 Fundamentals

 Performance

 OEM

 Application Server

 Grid Control

 Articles

 Prepare for OCP

Oracle SYNTAX

 Oracle Functions

 Oracle Syntax

 Oracle 10g Syntax

  PL/SQL Syntax

UNIX and more...

 UNIX for DBAs

 LINUX for DBAs

 DB using PHP

  A+ Certification

 Basics of JAVA  

 Tips of  SEO

Finance/Jobs

 Financial Aid

 Skilled

 Oracle

 Jobs

  Magazine

More Training

 Q & Answers

 SQL-PL/SQL

 DBA

 Developer

 Important Notes

 Case Studies

 9i New Features

 10g New Features

 10g Qs/As

 Grid Control

 OracleAS # I

 OracleAS # II

  LDAP and OID

  HTTP Server

 Instructor-Led

  Virtual Hosts

 Community Sharing

More to know...

Acknowledgement**

 FREE Legal Forms

 Who is who

 Market Place

 University Directory

 Advisory Articles

 Links...

 

 

More Resources by Google:

Topics:  Hands-On 06 - Populating table using PL/SQL

 

In this Hands-On, you create a table named "dept_stat".  The table contains four columns:  department name (dname), total number of employees (total_emplno), total salary of employees (total_sal), and average salary of employees (avg_sal).  And the department name should be a primary key.

 

Then write a PL/SQL block to populate the department statistics table (dept_stat) into the “dept_stat” table.  Use and modify the “test_for_loop” file from previous Hands-On.  Save the file as “test_for_loop2” at the iself directory.

 

    1- Create table.

    2- INSERT statement in PL/SQL block

    3- FOR LOOP statement.

    4- COMMIT statement in PL/SQL block.

.

Manuscript

Go to “MS-DOS.”

Change directory to the iself directory.  And login to “sqlplus” as “iself/schooling.”

Create a table named "dept_stat".

It should contain four columns:  department name, total number of employees, total salary, and average salary.  And define the department name as a primary key.

>>          create table dept_stat

                  (dname          varchar2(20) primary key,

                  total_empno          number(3),

        total_sal          number(8,2),

        avg_sal          number(8,2));

 

Table created.

 

Go to “Notepad”

Open the “test_for_loop” file from the iself directory.

 

Modify the PL/SQL block to populate the department stat table.

>>        declare

                        -- define department statistics

                        cursor c_ds is

                        select dname, count (*) ttemp,

sum(sal) ttsal, avg(sal) avsal

                                    from dept d, emp e

                                    where d.deptno = e.deptno

group by dname;

            begin

                        -- loop to read cursor record.

                        for v_ds in c_ds loop

                             -- insert into dept_stat

                             insert into dept_stat

                             values (v_ds.dname, v_ds.ttemp,

v_ds.ttsal, v_ds.avsal);

                        end loop;

                    -- save the insert transaction.

                    commit;

            end;

            /

 

 

In the “PL/SQL” body, insert each cursor record into the dept_stat table.

Save the insert transaction.

=

Save the file as “test_for_loop2” at the iself directory.

=

Go to “sqlplus.”

 

Run the file.

>> @test_for_loop2

 

Query the dept_stat table.

>> select * from dept_stat;

=

Now, you should practice this over and over, until you become a master at it.

Good Luck!

 
 
 
Google
 
Web web site