Write a block in PL/SQL to print the specific number of rows from a table.
SOLUTION TO THE ABOVE QUESTION
When solving this problem we will assume we have a table called 'Emp_Detail'
with Employee_id column,First_Name column,Last_name column, Salary column
we will write a code to display the total number of selected fields and shows
the total number of rows present in the table
SOLUTION CODE
DECLARE
CURSOR c_emp_detail IS
SELECT employee_id,first_name,last_name,salary
FROM emp_detail;
rec_emp_detail c_emp_detail%ROWTYPE;
BEGIN
OPEN c_emp_detail;
LOOP
FETCH c_emp_detail INTO rec_emp_detail;
EXIT WHEN c_emp_detail%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('Employees Details : '||' '||rec_emp_detail.employee_id ||' '||rec_emp_detail.first_name||' '||rec_emp_detail.last_name);
END LOOP;
DBMS_OUTPUT.PUT_LINE('Total number of rows : '||c_emp_detail%ROWCOUNT);
CLOSE c_emp_detail;
END;
Comments
Leave a comment