1. Oracle PLSQL Practical Interview Questions
set serveroutput on
DECLARE
lv_dept_no number :=10;
BEGIN
FOR i IN (
SELECT ename
FROM emp
WHERE deptno=lv_dept_no
) LOOP
dbms_output.put_line(i.ename);
END LOOP;
END;
/
-------------------------------------------------------------
set serveroutput on
DECLARE
lv_dept_no number :=10;
lv_ename emp.ename%type;
cursor c1 is SELECT ename
FROM emp WHERE deptno=lv_dept_no;
BEGIN
OPEN c1;
loop
fetch c1 into lv_ename;
exit when c1%notfound;
dbms_output.put_line(lv_ename);
END LOOP;
END;
/
-------------------------------------------------------------
set serveroutput on
DECLARE
type lv_name_list_type is table of emp.ename%type;
lv_emp_name_list lv_name_list_type := lv_name_list_type();
BEGIN
select ename
bulk collect into lv_emp_name_list
from emp
where deptno=10;
for i in lv_emp_name_list.first..lv_emp_name_list.last loop
dbms_output.put_line(lv_emp_name_list(i));
end loop;
END;
/
-------------------------------------------------------------
To learn more on cursor please check these links
To learn more on collection please check these links
Write a PLSQL block
to print the list of employee names
set serveroutput on
DECLARE
lv_dept_no number :=10;
BEGIN
FOR i IN (
SELECT ename
FROM emp
WHERE deptno=lv_dept_no
) LOOP
dbms_output.put_line(i.ename);
END LOOP;
END;
/
-------------------------------------------------------------
set serveroutput on
DECLARE
lv_dept_no number :=10;
lv_ename emp.ename%type;
cursor c1 is SELECT ename
FROM emp WHERE deptno=lv_dept_no;
BEGIN
OPEN c1;
loop
fetch c1 into lv_ename;
exit when c1%notfound;
dbms_output.put_line(lv_ename);
END LOOP;
END;
/
-------------------------------------------------------------
set serveroutput on
DECLARE
type lv_name_list_type is table of emp.ename%type;
lv_emp_name_list lv_name_list_type := lv_name_list_type();
BEGIN
select ename
bulk collect into lv_emp_name_list
from emp
where deptno=10;
for i in lv_emp_name_list.first..lv_emp_name_list.last loop
dbms_output.put_line(lv_emp_name_list(i));
end loop;
END;
/
-------------------------------------------------------------
To learn more on cursor please check these links
- https://youtu.be/X7WFuI5eTX4
- https://youtu.be/zXxNPDDWqOs
- https://youtu.be/5WXNBwpGeUw
- https://youtu.be/917dFN2Cc6M
- https://youtu.be/g4xK03ItH8Q
To learn more on collection please check these links