Creating Files Using PL/SQL?
Hi,
Is there a way to create a file using PL/Sql? It seems that the
utl_file package doesn't allow you to create a file. It only
allows you to read, write to a file that already exists there.
Thanks
Vic
Make sure the following is set in the init.ora:
UTL_FILE_DIR = /path/to/your/file/directory (for unix)
or
UTL_FILE_DIR = <drive>:\path\to\your\file\directory (for windows)
Similar Messages
-
How can I create an csv/excel file using pl/sql and then sending that file
How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.968776 wrote:
How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.You are trying to do it at a wrong place..
Whay do you want database (pl/sql) code to do these things?
Anyhow, you may be interested in :
{message:id=9360007}
{message:id=9984244} -
Creating a text file using pl/sql
how can one create a text file using pl/sql?
Say for example abcd.txt in the d: drive
(d:\abcd.txt)
on a windows nt server<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by bhrigu nagal ([email protected]):
thanks for your replies
I had already set the utl_file_dir parameter
I tried the utl package and wrote the following code but got some errors
declare
filehandler UTL_FILE.FILE_TYPE;
begin
filehandler:=UTL_FILE.fopen('d:/intel/','myfile.txt','w');
utl_file.put_line(filehandler,'look masjdfgsd\n');
utl_file.fclose(filehandler);
exception when utl_file.invalid_path then
raise_application_error(-20023,'bhrigu ,chk the path');
end;
the errors
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "SYS.UTL_FILE", line 101
ORA-06512: at "SYS.UTL_FILE", line 157
ORA-06512: at line 4
if u know what this is please tell me
thanks bhrigu
<HR></BLOCKQUOTE>
U need :
1) To have UTL_FILE_DIR param in the init file of the instance with the same directory (don't forget to stop and restart the base)
2) Handled the exceptions listed in the utl_file package (Oracle_home\rdbms\admin\utlfile.sql) in your source.
3) Turn set serveroutput on in SQL*Plus.
Run your procedure and see the error message to debug.
Good luck
null -
Downloading BLOB to a file using pl/sql toolkit
Created an Oracle Reports RDF file using the reports builder (9.0.2.x).
Uploaded the file into the database in a BLOB column using the following code:
>>>>
SET VERIFY OFF
DECLARE
p_bfile BFILE ;
p_blob BLOB ;
BEGIN
p_bfile := BFILENAME('CDR_REPORTS', '&1') ;
INSERT INTO RPTIDE (RPTID, RPTMODULE) VALUES ('&1', EMPTY_BLOB()) RETURNING
RPTMODULE INTO p_blob ;
DBMS_LOB.FILEOPEN(p_bfile, DBMS_LOB.FILE_READONLY);
DBMS_LOB.LOADFROMFILE(p_blob, p_bfile, DBMS_LOB.GETLENGTH(p_bfile));
DBMS_LOB.FILECLOSE(p_bfile);
COMMIT ;
END ;
<<<<<
Now when we try to download the same file using pl/sql web toolkit (code pasted
below), the file downloads fine (with exact same file size as before), but no
longer can open the file in Reports Builder anymore. Get "Cannot open file"
error in reports builder. Is it getting corrupt or am I doing something wrong?
>>>>
CREATE OR REPLACE PROCEDURE filedownload(p_rpt IN VARCHAR2) AS
p_file blob;
p_mime_type varchar2(50);
p_offset integer := 1;
p_len number;
p_buf RAW(32000);
p_buf_size integer:= 32000;
BEGIN
SELECT rptmodule, 'application/x-zip'
INTO p_file, p_mime_type
FROM rptide
WHERE rptid = p_rpt ;
OWA_UTIL.MIME_HEADER(p_mime_type);
p_len := DBMS_LOB.GETLENGTH(p_file);
WHILE p_offset < p_len LOOP
DBMS_LOB.READ(p_file, p_buf_size, p_offset, p_buf);
HTP.PRN(UTL_RAW.CAST_TO_VARCHAR2(p_buf));
p_offset := p_offset + p_buf_size;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN HTP.PRN('No document specified') ;
WHEN OTHERS THEN HTP.P('filedownload: '||SQLERRM);
END filedownload ;
<<<<<The answer to this problem was to set the NLS_LANGUAGE for the DAD to an 8-bit character set since the database charset was 8-bit. It seems, by default, the web toolkit assumes a 7-bit character set.
-
Generating text file using PL/SQL
can any body send sample program how to generate text file using PL/SQL program.I want to store table data into that text file.
Hi,
try this.
Thanks
CREATE OR REPLACE procedure write_index (TABLE_NAME_ACCEPT VARCHAR2) IS
id UTL_FILE.FILE_TYPE;
name VARCHAR2(20) := 'e:\db_coca\input';
err VARCHAR2(100);
ColNameLength Integer;
NumberoFColumns Integer;
num NUMBER;
i integer;
loc_query VARCHAR2(2000);
cursor_name INTEGER;
ret INTEGER;
l_const_name VARCHAR2(30);
CURSOR c_columns(i_Constraint_name VARCHAR2) IS
SELECT *
FROM all_cons_columns
WHERE CONSTRAINT_NAME = i_Constraint_name
order by table_name;
BEGIN
DBMS_OUTPUT.PUT_LINE('BEFORe OPEN');
--id := UTL_FILE.FOPEN('e:\db_coca\input',name,'w');
--IF UTL_FILE.IS_OPEN(id) THEN
-- DBMS_OUTPUT.PUT_LINE('Opened');
--ELSE
-- DBMS_OUTPUT.PUT_LINE('Still Closed');
--END IF;
DBMS_OUTPUT.PUT_LINE('AFTER OPEN');
--The table generation script
loc_query := 'Select CONSTRAINT_NAME from user_constraints ';
loc_query := loc_query || ' where owner = ' || '''CPS''';
loc_query := loc_query || ' AND CONSTRAINT_TYPE = ' || '''P''';
dbms_output.put_line('TABLE_NAME_ACCEPT = ' || TABLE_NAME_ACCEPT);
IF NOT (TABLE_NAME_ACCEPT IS NULL ) THEN
loc_query := loc_query || ' AND TABLE_NAME like ''';
loc_query := loc_query || TABLE_NAME_ACCEPT ;
loc_query := loc_query || '''';
END IF;
cursor_name := DBMS_SQL.OPEN_CURSOR;
dbms_output.put_line('Query = ' || loc_query);
DBMS_SQL.PARSE(cursor_name, loc_query, DBMS_SQL.v7);
dbms_output.put_line('After parse');
dbms_sql.DEFINE_COLUMN(cursor_name, 1,l_const_name, 30);
ret := DBMS_SQL.EXECUTE(cursor_name);
-- IF ret > 0 THEN
LOOP
dbms_output.put_line('return = ' || ret);
IF DBMS_SQL.FETCH_ROWS(cursor_name) > 0 THEN
dbms_sql.COLUMN_VALUE(cursor_name, 1,l_const_name);
-- dbms_sql.BIND_VARIABLE(cursor_name,
l_const_name,CONSTRAINT_NAME);
-- FOR C10 in Table_Loop Loop --The cursor
for the table name
Select COunt(*) INTO NumberoFColumns from
all_cons_columns
Where CONSTRAINT_NAME = l_const_name;
-- FOR C11 IN c_columns(l_const_name) LOOP
-- End loop;
-- UTL_FILE.PUT(id, ');');
ELSE EXIT;
END if; --THe 1 st cursor if is closed
End Loop; --The table loop ends here
DBMS_SQL.CLOSE_CURSOR(cursor_name);
-- END IF;
-- UTL_FILE.PUT_LINE(id,name);
-- UTL_FILE.PUT(id,'It worked and wrote to this file');
UTL_FILE.FCLOSE(id);
DBMS_OUTPUT.PUT_LINE('Successful write to file');
EXCEPTION
WHEN OTHERS THEN
err := SQLERRM;
num := SQLCODE;
DBMS_OUTPUT.PUT_LINE(err);
DBMS_OUTPUT.PUT_LINE(num);
DBMS_OUTPUT.PUT_LINE('Error in writing to file');
END write_index; -
Loading the data from a packed decimal format file using a sql*loader.
Hi ,
In one of the project i'm working here i have to load the data into oracle table from a file using a Sql*loader but the problem is the data file is in the packed decimal format so please let me know if there is any way to do this....I search a lot regarding this ..If anybody faced such type of problem ,then let me the steps to solve this.
Thanks in advance ,
Narasingarao.declare
f utl_file.file_type;
s1 varchar2(200);
s2 varchar2(200);
s3 varchar2(200);
c number := 0;
begin
f := utl_file.fopen('TRY','sample1.txt','R');
utl_file.get_line(f,s1);
utl_file.get_line(f,s2);
utl_file.get_line(f,s3);
insert into sampletable (a,b,c) values (s1,s2,s3);
c := c + 1;
utl_file.fclose(f);
exception
when NO_DATA_FOUND then
if utl_file.is_open(f) then utl_file.fclose(f); ens if;
dbms_output.put_line('No. of rows inserted : ' || c);
end;SY. -
Writing into Excel file using PL/SQL and formatting the excel file
Hi,
I am writing into a excel file using PL/SQL and I want to make the first line bold on the excel. Also let me know if there are any other formatting options when writing into excel.
Regards,
-AnandI am writing into a excel file using PL/SQL
Re: CSV into Oracle and Oracle into CSV
check that thread or search in this forum... -
Display data in log file using PL/SQL procedure
Just as srw.message is used in Oracle RDF Reports to display data in log file in Oracle Apps, similarly how it is possible to display data in log file using PL/SQL procedure?
Please also mention the syntax too.Pl post details of OS, database and EBS versions.
You will need to invoke the seeded FND_LOG procedure - see previous discussions on this topic
Enable debug for pl/sql
https://forums.oracle.com/forums/search.jspa?threadID=&q=FND_LOG&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
HTH
Srini -
Error- DBMS_STANDARD package must be created before using PL/SQL
HI
I am trying to run a very small and simple program on my Oracle81 personal edition on Win98.
I get this error when i want to execute the program
" package DBMS_STANDARD must be created before using PL/SQL "
What should i do to create the package??
Thank you
LinThe Member Feedback forum is for suggestions and feedback for OTN Developer Services. This forum is not monitored by Oracle support or product teams and so Oracle product and technology related questions will not be answered. We recommend that you post this question to the Database - General forum or the Installation forum.
The URLs are:
General Database Discussions
and
Database Installation -
Documention for creating portlets using pl/sql???
Hi,
can anyone help me get links for any kind of documentation about creating portlets using pl/sql for Oracle Application Server Portal 10g
thanks
MI think this will help out...
Check out Chapter 8, "Creating PL/SQL Portlets" in the Oracle Portal 10.1.4 Developer's Guide.
http://download-east.oracle.com/docs/cd/B14099_19/portal.1014/b14135/pdg_pdk_plsql.htm#BJEFHIBH -
Read XML File Using PL/SQL
Hi,
I have to read a XML file using PL/SQL. I am new to this so please explain in easy steps.
Regards,
SFSTEP - 2
SQL>
SQL> DECLARE
2 l_ctx dbms_xmlsave.ctxType ;
3 l_xml CLOB :=
4 '<?xml version="1.0" encoding="UTF-8" ?>
5 <NewDataSet>
6 <ROW>
7 <DEPARTMENT>BA52</DEPARTMENT>
8 <PCS_CONTRACT_TAG>MD-3GSM</PCS_CONTRACT_TAG>
9 <LOCATION>Australia</LOCATION>
10 <MAY_2006>21668</MAY_2006>
11 </ROW>
12 <ROW>
13 <DEPARTMENT>BA501</DEPARTMENT>
14 <PCS_CONTRACT_TAG>MD-3GSM</PCS_CONTRACT_TAG>
15 <LOCATION>China</LOCATION>
16 <MAY_2006>8166</MAY_2006>
17 </ROW>
18 <ROW>
19 <DEPARTMENT>BA522</DEPARTMENT>
20 <PCS_CONTRACT_TAG>MD-3GSM</PCS_CONTRACT_TAG>
21 <LOCATION>Australia</LOCATION>
22 <MAY_2006>21668</MAY_2006>
23 </ROW>
24 </NewDataSet>' ;
25 BEGIN
26 l_ctx := dbms_xmlsave.newContext(targetTable => 'XML_INSERT');
27 dbms_output.put_line(dbms_xmlsave.insertXML(ctxHdl => l_ctx,
28 xDoc => l_xml) ||
29 ' rows inserted.');
30 dbms_xmlsave.closeContext(l_ctx);
31 END;
32 /
3 rows inserted.
PL/SQL procedure successfully completed.Regards.
Satyaki De. -
I accidentally created files using a Free Trial version of InDesign. Now the files are gone. Where did they go? How do I get them back? I pay for Creative Cloud... but used the wrong login apparently.
Files you save don't disappear, even if you no longer have the software that created them. They're right where you saved them.
-
Can I create a file using pl/sql code in application server ?
Hi
I wanted to create a file(any kind of file .txt .csv .exe etc..) using pl/sql code in application server?
Please help me with an example...in this regard
Regards
Sa864334 wrote:
I wanted to create a file(any kind of file .txt .csv .exe etc..) using pl/sql code in application server?And how is this "file" to be delivered?
Files can be created by PL/SQL code and stored in the Oracle database as CLOBs. This a fairly easy and robust process. It runs entirely in the database. It conforms to transaction processing. The "file" (as a CLOB) resides in the database and can thus be secured via database security, is part of database backups and so on.
The basic issue is how to deliver the contents of the CLOB to the user. If via FTP, then the database can directly FTP the contents of the CLOB to the FTP server as a file. If via HTTP, the database can deliver the CLOB as a HTTP download directly to the web browser.
If the client is Java or .Net, then the CLOB contents can be delivered via SQL or DBMS_LOB or a custom PL/SQL interface.
In such cases, there is no need to step outside the secure and flexible database environment and create a physical o/s file in the wild (outside the controls of database security, data integrity and transaction processing). This is thus recommended and is the preference. -
Hello All:
I have an requirement of generating a PDF file using Oracle PL SQL program. Can anyone please let me know the procedure/code of doing this?
Thanks,
k Ramesh GuptaI have steps to generate Excel sheet output, apply appropriate content-type for PDF in the PL/SQL written below, to get the same in PDF. i suppose it should be application/pdf
1. Create a custom DAD if required using Enterprise Manager Console of MidTier for HTTP Server or use Portal DAD itself to implement the solution.
2. Create a new procedure (a webdb solution) to stream the HTML for the excel sheet report which will be downloaded.
a. Login to Portal schema through SQL*Plus or the respective DAD based schema if custom DAD is created. (below example is created in custom DAD - 'scott').
SQL>CREATE OR REPLACE
PROCEDURE generateCsv
as
cursor p_emp is select * from PORTAL_DEMO.EMP;
begin
owa_util.mime_header( 'application/vnd.ms-excel', False ); -- Here change the content-type to PDF Format accordingly
htp.print('Content-Disposition: attachment;filename="pvasista.csv"');
owa_Util.Http_Header_Close;
for v_emp_cur in p_emp
LOOP
htp.p (v_emp_cur.ename || ',' || v_emp_cur.deptno || chr(13));
END LOOP;
end;
SQL> grant execute on generateCsv to public;
For education purpose getting the report of employee and deptno of al employees from PORTAL_DEMO.EMP table. Implement the necessary query/ Business Logic accordingly.
b. Now access http://midtier_host:port/pls/dad_name/generateCsv, will download a .csv based excel file report as shown in the screenshot below,
3. Open the Portal Page where the link is to be added, createa URL Item Link and add the above URL, select option "Open in new browser window"
4. It can also be enhanced to have filtering enabled on the report by using Portal Form using Option, "Form based on stored procedure" and selecting the above stored procedure. -
How do I create a binary file using PL/SQL
Hi
Can you help me with writing a binary file in PL/SQL? I like to load binary data from data file, process in database then write to a new binary file.
Thank you very much in advance.
regrds
YongdongDBMS_LOB won't help you write a BLOB to disk.
You need to an external procedure to do that. Eric K's java works great and he's helped me with his solution and probably about a thousand others.
Doing a search on this forum will yield many discussions on this often regurgitated topic.
Maybe you are looking for
-
Fill In The Blank / Sequence Questions
Is it possible to have a fill in the blank question in captivate (4 or 5) that is scored according to how many options the user got correct? For example: If you use 4 grams of 'b' you will need _____ grams of 'x', _____ grams of 'y' and ____ grams of
-
Line items AND GENERIC EXTRACTION
what does line items exactly mean in DATASOURCES AND WHAT ARE DELTA TYPE EXTRACTIONS IN GENERIC TIME STAMPING CALENDAR DAY NUMERICAL POINTER COULD ANY PLEASE EXPLAIN THE DIFFERNCE AND IN WHAT SCENARIOS WE USE IT ... LOOKING FOR YOUR REPLY
-
Hi, i am trying to use dynamic configuration variable DCJMSMessageQueue as a condition for determining the receiver within the Receiver Determiniation. I can see the value in the DCJMSMessageQueue, but the condition is not applied. Have anyone tried
-
ContactSheetX 2.1 Released
Cross-post: ContactSheetX 2.1 Released
-
Dear Experts, Can you help explain how can I specify the agent in workflow by coding ? In the following screenshot, what is the meaning of "Resp.Resolver Name" ? and how can I define it or modify the logic? Actually, I want the workflow read the agen