create or replace procedure proc1 is
vfileID UTL_FILE.file_type;
vstring varchar2(2000);
cursor c1 is select empno from emp;
c1empno number(4);
begin
vstring:='empno,ename,job,mgr,hiredate,sal,comm,deptno';
vfileID:=UTL_FILE.fopen('D:\','HARI1.DAT','W');
UTL_FILE.Put(vfileid, vstring);
UTL_FILE.New_Line(vfileid);
open c1;
loop
fetch c1 into c1empno;
exit when c1%notfound;
SELECT EMPNO||','||
ENAME||','||
JOB||','||
MGR||','||
HIREDATE||','||
SAL||','||
NVL(COMM,0)||','||
DEPTNO
INTO vstring
FROM EMP
WHERE EMPNO=c1empno;
UTL_FILE.Put(vfileid, vstring);
UTL_FILE.New_Line(vfileid);
end loop;
close c1;
UTL_FILE.fclose(vfileID);
exception
when others then
DBMS_OUTPUT.PUT_LINE('SYSTEM ERROR');
end;