Tuesday, June 5, 2012

convert the typed form input or typed text into the file

1) create an application with blank page .
2) ADD the Text area item (P1_ADD) .
3) Create a Button (Name:MAKEFILE, REQUEST:MAKEFILe)
Now when the Make file button is pressed you need to create a file and append the content of the P1_ADD to that file .


To do this , we need to create A Procedure as

create or replace procedure writefile(path varchar2,filename varchar2,content varchar2)
is
output_file utl_file.file_type;
begin
output_file := utl_file.fopen (path ,filename , 'W');
utl_file.put_line (output_file, content );
-- utl_file.put_line (output_file,'second added here ');
utl_file.fclose(output_file);

--exception
-- when others then null;
end;
/



Note: - the Path which we give here will be the relative , not absolute path .

EX:- if ur files need to be placed in E:\myfiles
then u need to do following .


Login to oracle :sys as sysdba;

create or replace directory MYDIR as "E:\myfiles";

Now to make this accesible to your schema on which the application is created .

U need to

GRANT READ,WRITE ON DIRECTORY mydir TO myschema;


Incase u wanna create the directory with in the same schema then ur schema must have the rights to create the directory .

GRANT CREATE ANY DIRECTORY TO MYSCHEMA;

So , now u can create the directory using the same schema also .


Now on Page1 , create a process and call this procedure on the Click of the MAKEFILE button .




NOTE:- MYDIR needs to be in uppercase for sure.
Declare
l_n_fileno number;

begin
select demo_order_items_seq.nextval into l_n_fileno from dual;
writefile('MYDIR',l_n_fileno||'.txt',:P1_ADD);
end;

This will generate the files and name it using seq .









SEE refernces:-

http://www.cs.umbc.edu/portal/help/oracle8/server.815/a68001/utl_file.htm


http://forums.oracle.com/forums/thread.jspa?messageID=9169498�

http://www.adp-gmbh.ch/ora/plsql/utl_file.html

http://psoug.org/reference/utl_file.html

No comments:

Post a Comment