Answer to Question #258940 in Databases | SQL | Oracle | MS Access for Tarurendra Kushwah

Question #258940

Write a block in PL/SQL to print the specific number of rows from a table.


1
Expert's answer
2021-11-03T17:48:25-0400


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;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS