Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

DECLARE
  CURSOR emp_cur IS
    SELECT first_name,last_name, salary FROM employees
    WHERE ROWNUM < 8
    ORDER BY first_name;

   emp_fname employees.first_name%TYPE;	
   emp_lname employees.last_name%TYPE;
   emp_sal   employees.salary%TYPE;
BEGIN
  OPEN emp_cur;
  LOOP
    FETCH emp_cur INTO emp_fname,emp_lname, emp_sal;
    IF emp_cur%NOTFOUND THEN 
      EXIT;
    ELSE  
      DBMS_OUTPUT.PUT_LINE
        (rpad('Name: ' || emp_fname||' '|| emp_lname ,30)|| 'salary:  ' || emp_sal);
    END IF;
  END LOOP;
END;
/
 

Sample Output:

SQL> /
Name: Alexander Hunold        salary:  9000
Name: Bruce Ernst             salary:  6000
Name: David Austin            salary:  4800
Name: Lex De Haan             salary:  17000
Name: Neena Kochhar           salary:  17000
Name: Steven King             salary:  24000
Name: Valli Pataballa         salary:  4800

PL/SQL procedure successfully completed.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now