top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to send data into file.txt from the database using W mode Oracle PLSQL

+3 votes
446 views
How to send data into file.txt from the database using W mode Oracle PLSQL
posted Sep 15, 2014 by Suchithra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

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;

answer Sep 15, 2014 by Arun Gowda
Similar Questions
+1 vote

when ever i run the anonymous plsql block, sql*plus request me enter the parameter input value

I have a variable value like customer_name='xxxcust & lt pvt'

please help me

+1 vote

Do i need to write in PL/SQL or is it possible in SQL query?

...