Home » Other » Training & Certification » Block structure
Block structure [message #275543] Sun, 21 October 2007 09:12 Go to next message
mrparr
Messages: 9
Registered: October 2007
Junior Member
In using a block structure, how can I design a PL/SQl program that will enable a screen display of all my records? I am a beginner and trying to figure out what to put in the declare statement and the executable statement. I have created a table and even placed five sample records. I need to show an output.

SQL> select*
  2  from records;

EMPLOYEE_CODE EMPLOYEE_SSN FIRST_NAME LAST_NAME  EMPLOYEE_ HOURLY_RATE
------------- ------------ ---------- ---------- --------- -----------
ANNUAL_SALARY
-------------
            1    123541236 John       Brown      01-JAN-05          11
        20750

            2    789541254 Cynthia    Green      05-FEB-06          11
        21865

            3    654321122 Steve      White      16-MAR-04          12
        23001


EMPLOYEE_CODE EMPLOYEE_SSN FIRST_NAME LAST_NAME  EMPLOYEE_ HOURLY_RATE
------------- ------------ ---------- ---------- --------- -----------
ANNUAL_SALARY
-------------
            4    123785555 Gail       Black      20-MAY-07          12
        24156

            5      4047852 Fred       Jones      03-APR-07          13
        25291
Re: Block structure [message #275544 is a reply to message #275543] Sun, 21 October 2007 10:09 Go to previous messageGo to next message
Michel Cadot
Messages: 64140
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:

I am a beginner

So why put the question in Expert forum?

Quote:

how can I design a PL/SQl program that will enable a screen display of

Why do you think you need PL/SQL?
PL/SQL does not display anything.

Quote:

I need to show an output.

Which one? With which tool?

Please read and follow OraFAQ Forum Guide.
Please always post your Oracle version (4 decimals).

Regards
Michel
Re: Block structure [message #275548 is a reply to message #275543] Sun, 21 October 2007 10:48 Go to previous message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
If I understood the question, DBMS_OUTPUT package used in a cursor loop is what you are looking for. This is a sample code:
BEGIN
  FOR cur_r IN (SELECT employee_code, employee_ssn, first_name
                FROM records)
  LOOP
    dbms_output.put_line(cur_r.employee_code ||' '||
	                 cur_r.employee_ssn  ||' '||
	                 cur_r.first_name
	                );
  END LOOP;
END; 
Don't forget to SET SERVEROUTPUT ON before executing the script (if SQL*Plus is a tool you use; if not, find how to enable the output in your tool).
Previous Topic: Count,SUM, AVG of table data using PL/SQL
Next Topic: does this need a union?
Goto Forum:
  


Current Time: Fri Dec 09 07:53:14 CST 2016

Total time taken to generate the page: 0.10469 seconds