CURSOR C1 IS
SELECT e.empno
, e.ename
, TO_CHAR(e.hiredate,'DD-MON-YYYY') hiredate
, e.sal
, e.deptno
, d.dname
FROM emp e
, dept d
WHERE e.deptno = d.deptno;
vfile_handle UTL_FILE.file_type;
v_directory VARCHAR2 (2000);
v_file VARCHAR2 (240);
BEGIN
dbms_output.put_line( 'Program Start');
vfile_handle := UTL_FILE.FOPEN('/usr/tmp/LR12DEV2','Emp_Data.csv','W');
UTL_FILE.PUT_LINE(vfile_handle,''
|| ',' ||''
|| ',' ||'Revenue Amortizations Functional Report'
);
UTL_FILE.NEW_LINE(vfile_handle);
UTL_FILE.NEW_LINE(vfile_handle);
UTL_FILE.PUT_LINE(vfile_handle,
'EMPNO'
|| ',' ||'ENAME'
|| ',' ||'HIREDATE'
|| ',' ||'SAL'
|| ',' ||'DEPTNO'
|| ',' ||'DNAME'
);
FOR rec IN c1
LOOP
dbms_output.put_line( 'Loop Start- Empno'||rec.empno);
UTL_FILE.PUT_LINE(vfile_handle,
'"'||rec.empno||'"'
|| ',' ||'"'||rec.ENAME||'"'
|| ',' ||'"'||rec.HIREDATE||'"'
|| ',' ||'"'||rec.SAL||'"'
|| ',' ||'"'|| rec.DEPTNO||'"'
|| ',' ||'"'||rec.DNAME||'"'
);
END LOOP;
UTL_FILE.FCLOSE(vfile_handle);
dbms_output.put_line( 'Program End');
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line('Program Exception:'||SQLERRM);
END;
/
Sample output
------------------------------------------------------------------
,,Revenue Amortizations Functional Report
EMPNO,ENAME,HIREDATE,SAL,DEPTNO,DNAME
"7782","CLARK","09-JUN-1981","2450","10","ACCOUNTING"
"7934","MILLER","23-JAN-1982","1300","10","ACCOUNTING"
"7839","KING","17-NOV-1981","5000","10","ACCOUNTING"
"7902","FORD","03-DEC-1981","3000","20","RESEARCH"
"7788","SCOTT","09-DEC-1982","3000","20","RESEARCH"
"7566","JONES","02-APR-1981","2975","20","RESEARCH"
"7369","SMITH","17-DEC-1980","800","20","RESEARCH"
"7876","ADAMS","12-JAN-1983","1100","20","RESEARCH"
"7521","WARD","22-FEB-1981","1250","30","SALES"
"7654","MARTIN","28-SEP-1981","1250","30","SALES"
"7844","TURNER","08-SEP-1981","1500","30","SALES"
"7900","JAMES","03-DEC-1981","950","30","SALES"
"7499","ALLEN","20-FEB-1981","1600","30","SALES"
"7698","BLAKE","01-MAY-1981","2850","30","SALES"
No comments:
Post a Comment