On Mon, 3 May 1999 DCarter328@aol.com wrote:

> I NEED CODES FOR THESE PROBLEMS.
> 
> 1. CREATE PL/SQL ANONYMOUS BLOCK THAT DISPLAYS THE WORDS "I AM LEARNING 
> PL/SQL".

SET SERVEROUTPUT ON SIZE 10000
BEGIN
   dbms_output.put_line ('I AM LEARNING PL/SQL');
END;
/

> 
> 2. CREATE PL/SQL ANONYMOUS BLOCK THAT COMPUTES AND DISPLAYS THE AVERAGE 
> STARTING AGE OF ALL EMPLOYEES. (CREATE AN EMPLOYEE TABLE AND INPUT 3 RECORDS)

CREATE TABLE EMPLOYEE
(LASTNAME  VARCHAR2(100),
 FIRSTNAME VARCHAR2(100),
 AGE       NUMBER
)
/
INSERT INTO EMPLOYEE VALUES ('Gates','Bill',39);
INSERT INTO EMPLOYEE VALUES ('Ballmer','Steve',42);
INSERT INTO EMPLOYEE VALUES ('Weisman','Irving',41);

SET SERVEROUTPUT ON SIZE 1000
DECLARE
   avg_age NUMBER;
BEGIN
   SELECT avg(age) INTO avg_age
   FROM EMPLOYEE;
   DBMS_OUTPUT.PUT_LINE('The average age is...');
   DBMS_OUTPUT.PUT_LINE(avg_age);
END;
/    

> 
> CAN YOU PLEASE ALSO TELL ME HOW TO PRINT USING THE SPOOL COMMANDS AT THE 
> BEGINNING AND THE ENDING OF THE CODES.

You use the "SPOOL file_name.lst" and "SPOOL OFF" commands. For example,
to print the commands and the results, do:

SPOOL myfile.lst
{command1};
{command2};
{...};
SPOOL OFF

Best regards,

-Ari Kaplan
Independent Oracle DBA Consultant

<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
<-> For 280+ Oracle tips, visit my Web Page:                      <->
<->                                                               <->
<->             www.arikaplan.com                                 <->
<->                                                               <->
<->             email: akaplan@interaccess.com                    <->
<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->

Back to Ari Kaplan's Home Page > Back to Ari Kaplan's Home Page