Here is an example of a PL/SQL program to display student details:
Example
DECLARE -- Declare variables to hold student details student_name VARCHAR2(100); student_id NUMBER; student_grade NUMBER; -- Declare a cursor to fetch student details from the database CURSOR student_cur IS SELECT name, id, grade FROM students; BEGIN -- Open the cursor OPEN student_cur; -- Loop through each student record LOOP -- Fetch the student details FETCH student_cur INTO student_name, student_id, student_grade; -- Exit the loop if there are no more student records EXIT WHEN student_cur%NOTFOUND; -- Print the student details DBMS_OUTPUT.PUT_LINE(student_name || ', ' || student_id || ', ' || student_grade); END LOOP; -- Close the cursor CLOSE student_cur; END;
The output of this program would be a list of student details in the following format:
Student Name, Student ID, Student Grade John Doe, 123456, 90 Clarky, 98765, 50 Statement processed.
This example uses a cursor to fetch student records from a students
table and then loops through each record, printing the student details. You can modify the program to meet your specific needs and requirements.
You can use the following SQL statement to create the table to use it for the above example:
CREATE TABLE students ( name VARCHAR2(100) NOT NULL, id NUMBER NOT NULL, grade NUMBER );
This statement creates a students
table with three columns: name
, id
, and grade
. The name
and id
columns are required and cannot contain NULL values, while the grade
column is optional.
Once you have created the table, you can insert records into it using an INSERT
statement:
INSERT INTO students (name, id, grade) VALUES ('John Doe', 123456, 90); INSERT INTO students (name, id, grade) VALUES ('Clarky', 98765, 50); Commit;
This statement inserts a new student record with the name "John Doe", ID 123456, and a grade of 90. You can insert as many records as you need to populate the table with student data.
After you have created the table and inserted records into it, you can use the PL/SQL program above to display the student details.