Use of cursor (Explicit) in SQL
Declare
Cursor emp_cur is
Select emp.ename,dept.dname,dept.deptno
From emp,dept
Where emp.deptno = dept.deptno;
Begin
For emp_rec in emp_cur loop
If emp_rec.deptno = 30 then
Dbms_output.put_line('Employee'||' '||emp_rec.ename||' '||'work in the'||' '||emp_rec.dname||' '||'Department');
End if;
End loop;
End;
So find these Result:
Employee ALLEN work in the SALES Department
Employee WARD work in the SALES Department
Employee MARTIN work in the SALES Department
Employee BLAKE work in the SALES Department
Employee TURNER work in the SALES Department
Employee JAMES work in the SALES Department
Declare
Cursor emp_cur is
Select emp.ename,dept.dname,dept.deptno
From emp,dept
Where emp.deptno = dept.deptno;
Begin
For emp_rec in emp_cur loop
If emp_rec.deptno = 30 then
Dbms_output.put_line('Employee'||' '||emp_rec.ename||' '||'work in the'||' '||emp_rec.dname||' '||'Department');
End if;
End loop;
End;
So find these Result:
Employee ALLEN work in the SALES Department
Employee WARD work in the SALES Department
Employee MARTIN work in the SALES Department
Employee BLAKE work in the SALES Department
Employee TURNER work in the SALES Department
Employee JAMES work in the SALES Department
No comments:
Post a Comment