BLOB data in the directory using UTL_FILE
Hi all"I wrote a procedure to store BLOB data in the directory using * UTL_FILE.
Using the package UTL_FILE, I created procedure below. Procedure runs successfully without any error, but the file is not written to the directory. Pls find my procedure below.
* CREATE OR REPLACE PROCEDURE Write_BLOB_To_File
AS
v_lob_loc BLOB;
v_buffer RAW (32767).
v_buffer_size directory.
v_amount directory.
v_offset Number (38): = 1;
v_chunksize INTEGER.
v_out_file UTL_FILE. TYPE_DE_FICHIER;
BEGIN
-- | SELECT THE LOB LOCATOR
SELECT an attachment
IN v_lob_loc
ATTACHMENT
WHERE attachment_id = 720;
-- | DISCOVER THE CHUNKSIZE FOR THAT LOB COLUMN
v_chunksize: = DBMS_LOB. GETCHUNKSIZE (v_lob_loc);
IF (v_chunksize < 32767) CAN
v_buffer_size: = v_chunksize;
ON THE OTHER
v_buffer_size: = 32767;
END IF;
v_amount: = v_buffer_size;
-- | OPENING A LOB IS OPTIONAL
DBMS_LOB. OPEN (v_lob_loc, DBMS_LOB. LOB_READONLY);
-- | WRITE THE CONTENT OF A LOB IN A FILE
v_out_file: = UTL_FILE. FOPEN)
location = > "EXAMPLE_LOB_DIR"
filename = > "Test.doc."
OPEN_MODE = > 'w ',.
max_linesize = > 32767);
While v_amount > = v_buffer_size
LOOP
DBMS_LOB. READ)
lob_loc = > v_lob_loc,
amount = > v_amount,
offset = > v_offset,
buffer = > v_buffer);
v_offset: = v_offset + v_amount;
UTL_FILE. () PUT_RAW
file = > v_out_file,
buffer = > v_buffer,
AutoFlush = > true);
UTL_FILE. FFLUSH (file = > v_out_file);
-UTL_FILE. NEW_LINE (file = > v_out_file);
END LOOP;
UTL_FILE. FFLUSH (file = > v_out_file);
UTL_FILE. FCLOSE (v_out_file);
-- | THE LOB OF CLOSING IS REQUIRED IF YOU OPENED IT
DBMS_LOB. Close (v_lob_loc);
END; *
I have provided the necessary privileges for the schema and directory. But the file is not written to the directory. can you please advise me
OPEN_MODE-online 'w' change to open_mode-online "wb."
Tags: Database
Similar Questions
-
storing BLOB data in the directory
Hi all
"I wrote a procedure to store BLOB data in the directory using * UTL_FILE.
*
Using the package UTL_FILE, I created procedure below. Procedure runs successfully without any error, but the file is not written to the directory. Pls find my procedure below.
CREATE OR REPLACE PROCEDURE Write_BLOB_To_File
AS
v_lob_loc BLOB;
v_buffer RAW (32767).
v_buffer_size directory.
v_amount directory.
v_offset Number (38): = 1;
v_chunksize INTEGER.
v_out_file UTL_FILE. TYPE_DE_FICHIER;
BEGIN
-- | SELECT THE LOB LOCATOR
SELECT an attachment
IN v_lob_loc
ATTACHMENT
WHERE attachment_id = 720;
-- | DISCOVER THE CHUNKSIZE FOR THAT LOB COLUMN
v_chunksize: = DBMS_LOB. GETCHUNKSIZE (v_lob_loc);
IF (v_chunksize < 32767) CAN
v_buffer_size: = v_chunksize;
ON THE OTHER
v_buffer_size: = 32767;
END IF;
v_amount: = v_buffer_size;
-- | OPENING A LOB IS OPTIONAL
DBMS_LOB. OPEN (v_lob_loc, DBMS_LOB. LOB_READONLY);
-- | WRITE THE CONTENT OF A LOB IN A FILE
v_out_file: = UTL_FILE. FOPEN)
location = > "EXAMPLE_LOB_DIR"
filename = > "Test.doc."
OPEN_MODE = > 'w ',.
max_linesize = > 32767);
While v_amount > = v_buffer_size
LOOP
DBMS_LOB. READ)
lob_loc = > v_lob_loc,
amount = > v_amount,
offset = > v_offset,
buffer = > v_buffer);
v_offset: = v_offset + v_amount;
UTL_FILE. () PUT_RAW
file = > v_out_file,
buffer = > v_buffer,
AutoFlush = > true);
UTL_FILE. FFLUSH (file = > v_out_file);
-UTL_FILE. NEW_LINE (file = > v_out_file);
END LOOP;
UTL_FILE. FFLUSH (file = > v_out_file);
UTL_FILE. FCLOSE (v_out_file);
-- | THE LOB OF CLOSING IS REQUIRED IF YOU OPENED IT
DBMS_LOB. Close (v_lob_loc);
END;
*
I have provided the necessary privileges for the schema and directory. But the file is not written to the directory. can you please advise meNote the name of this forum is Developer SQL *(Not for general SQL/PLSQL questions) *, both for issues with the SQL Developer tool. Please post these questions under the dedicated SQL and PL/SQL forum only and not to repeat the discussions.
Kind regards
K. -
problem to extract data from the database using UTL_FILE
Dear members
I make use of series for the SUBSTR and INSTR function to extract the fields of a data file and carve out spaces based on the number of post mentioned in the Excel worksheet. I was able to extract the first 3 areas namely, customer, manufacturer, product, but for quantity, requested delivery date, price, I can't do it.
the flat file structure is as follows:
Sample data in the flat file is as follows:Field Position From Position To CUSTOMER_NAME 1 30 MANUFACTURER 31 70 PRODUCT_NAME 71 90 QUANTITY 91 95 REQUESTED_SHIP_DATE 96 115 REQUESTED_PRICE 116 120
My program code is the following:BESTBUY SONY ERICSSON W580i 25 1-AUG-2008 50 BESTBUY SAMSUNG BLACKJACK 50 15-JUL-2008 150 BESTBUY APPLE IPHONE 4GB 50 15-JUL-2008 BESTBUY ATT TILT 100 15-JUN-2008 BESTBUY NOKIA N73 50 15-JUL-2008 200
I was able to extract the first 3 fields of the file data, but when I use the same SUBSTR and INSTR functions to extract then three fields I am unable to do so (I get 5, 6 on the ground as well when I extract the 4th field). I've hardcoded the position values in these functions, such as mentioned in the structure of flat file.CREATE OR REPLACE PROCEDURE ANVESH.PROC_CONVERSION_API(FILE_PATH IN VARCHAR2,FILE_NAME IN VARCHAR2) IS v_file_type utl_file.file_type; v_buffer VARCHAR2(1000); V_CUSTOMER_NAME VARCHAR2(100); V_MANUFACTURER VARCHAR2(50); V_PRODUCT_NAME VARCHAR2(50); V_QUANTITY NUMBER(10); V_REQ_SHIP_DATE DATE; V_REQ_PRICE NUMBER(10); V_LOG_FILE utl_file.file_type; V_COUNT_CUST NUMBER; V_COUNT_PROD NUMBER; v_start_pos number := 1; v_end_pos number; BEGIN DBMS_OUTPUT.PUT_LINE('Inside begin 1'); v_file_type := UTL_FILE.fopen(FILE_PATH, FILE_NAME, 'r',null); DBMS_OUTPUT.PUT_LINE('Inside begin 1.1'); LOOP BEGIN DBMS_OUTPUT.PUT_LINE('Inside begin 2'); UTL_FILE.GET_LINE (v_file_type,v_buffer); DBMS_OUTPUT.PUT_LINE('Inside begin 2.1'); select instr('v_buffer',' ', 1, 1) - 1 --into v_end_pos from dual; select substr('v_buffer', 1, 7) --into V_CUSTOMER_NAME from dual; select instr('v_buffer', ' ', 31, 2)-1 --into v_end_pos from dual; select trim(substr('v_buffer', 28, 43)) --into V_MANUFACTURER from dual; select instr('v_buffer', ' ', 45, 1) - 1 --into v_end_pos from dual; select trim(substr('v_buffer', 44, 45)) --into V_PRODUCT_NAME from dual; V_LOG_FILE := UTL_FILE.FOPEN(FILE_PATH, 'LOG_FILE.dat', 'A'); IF (V_QUANTITY > 0) THEN SELECT COUNT (*) INTO V_COUNT_CUST FROM CONVERSION_CUSTOMERS WHERE CUSTOMER_NAME = V_CUSTOMER_NAME; IF(V_COUNT_CUST > 0) THEN SELECT COUNT(*) INTO V_COUNT_PROD FROM conversion_products WHERE PRODUCT_NAME = V_PRODUCT_NAME; IF(V_COUNT_PROD >0) THEN INSERT INTO XXCTS_ORDER_DETAILS_STG VALUES (V_CUSTOMER_NAME, V_PRODUCT_NAME, V_MANUFACTURER, V_QUANTITY, V_REQ_SHIP_DATE, V_REQ_PRICE, 'ACTIVE', 'ORDER TAKEN'); ELSE DBMS_OUTPUT.PUT_LINE('PRODUCT SHOULD BE VALID'); UTL_FILE.PUT_LINE(V_LOG_FILE, 'PRODUCT SHOULD BE VALID'); END IF; ELSE DBMS_OUTPUT.PUT_LINE('CUSTOMER SHOULD BE VALID'); UTL_FILE.PUT_LINE(V_LOG_FILE, 'CUSTOMER SHOULD BE VALID'); END IF; ELSE DBMS_OUTPUT.PUT_LINE('QUANTITY SHOULD BE VALID'); UTL_FILE.PUT_LINE(V_LOG_FILE, 'QUANTITY SHOULD BE VALID'); END IF; EXCEPTION WHEN NO_DATA_FOUND THEN EXIT; END; END LOOP; END; /
It would be great if someone can tell me how to extract the three fields in the flat file.
Thank you
RomaricRomaric,
Why you use v_end_pos to trim spaces when you know the beginning and end of all columns positions?
I do not see the code when you check out the values of other 3 columns (Qty, Date & price).You can use substr underneath rather do SELECT each time.
V_CUSTOMER_NAME := SUBSTR(v_buffer,1,30); V_MANUFACTURER := SUBSTR(v_buffer,31,70); V_PRODUCT_NAME := SUBSTR(v_buffer,71,90); V_QTY := SUBSTR(v_buffer,91,95); V_SHIP_DATE := SUBSTR(v_buffer,96,115); V_PRICE := SUBSTR(v_buffer,116,120);
-Raj
-
Writing a file on the network using UTL_FILE
Hi all
Can we write a file on a path to the network using UTL_FILE. I have full access on the network folder, which I use as directory object.
Details of the environment:
Oracle Database 10g XE
WIN XP
Concerning
SISSMON wrote:
but I remember not so utl_file works with UNC paths or not, just try it & see!To do this, if the account that runs the writing has permissions to the destination. We use UNC paths in some of our environments.
-
How to insert data into the database using smartview
Hello
I am trying to insert data into the database using * "Send data" * button on the Ribbon of Essbase.
My database is empty.
I opened an ad hoc network, it returns * "#missing" * in all cells
I have modified the cells and provided data in the cells that I want to. Now, I supported on * "Send data" * button.
It just reloaded the adhoc grid instead of submit data, I rechecked the data through data console Administrative Service are not inserted.
I am following the right way to insert data? If not, could you please suggest me how (Populate) insert default data in the database?
--
VINETYou go about it the right way, once you have submitted if you réactualisiez then data values should be there, if you POV is against members of dynamic calc and then data not written to the database, you need to check the Member properties of your POV.
See you soon
John
http://John-Goodwin.blogspot.com/ -
My select statement fails with the error:
The ORA-19011 string buffer too small
The select statement looks like:
SELECT TO_CLOB)
XMLELEMENT ("accounts",
XMLELEMENT ("count",
XMLATTRIBUTES)
rownum AS "recordId."
To_date('20130520','YYYYMMDD') AS "datestarted."
123456 AS "previousBatchId."
56789 AS 'previousRecordId '.
),
....
.... .
.....
XMLFOREST)
SIG_ROLE AS "SignatoryRole."
To_char(TRANSFER_DATE,'YYYY-mm-DD') AS "TransferDate."
NVL(Reason,0) AS 'reason '.
) AS the 'transfer '.
)
()) AS CRDTRPT
OF ANY_TABLE;
- It looks like I can choose only 4000 characters using the SELECT statement (please, correct me if I'm wrong)
I'd use the XMLGEN package. But the environment team says no mounted drives in the future with the arrival of the EXADATA.
NO HARD DRIVE MOUNTED, NO ACCESS TO THE DATABASE DIRECTORIES
No UTL_FILE
I need to use the REEL spool the resulting XML data of the SELECT query.
SQL is a standard in my org, but I can do with a PL/SQL solution also to load data into a table (cannot use a COIL with PL/SQL)
What I do is:
- a column of type CLOB to a xml_report of the loading of the above SELECT query table
- Then using SELECT * FROM xml_report to SPOOL the data to a file report.xml
No need of XMLTYPE data behind. Xml data stream is fine for me.
In addition, I need to validate the XML file, also using XSD.
Problem is that the resulting lines of the select query are supposed to be from 15000 to 20000 bytes long.
Oracle database version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
A Suggestion or a solution to this problem would be appreciated.
(Sorry for the use of "BOLD", just to make it more readable and highlight the imp points)
Bravo!
Rahul
It looks like I can choose only 4000 characters using the SELECT statement (please, correct me if I'm wrong)
You use the right method.
There is an implicit conversion from XMLType to the data type VARCHAR2 as expected by the function TO_CLOB, where the limitation, and the error.
To serialize XMLType to CLOB, use the XMLSerialize function:
SELECT XMLSerialize (DOCUMENT
XMLELEMENT ("accounts",
...
)
)
OF ANY_TABLE;
For the rest of the requirement, I wish you good luck trying to spool the XML correctly.
You may need to play around with the SET LONG and SET LONGCHUNKSIZE commands to operate.
-
CANNOT ACCESS THE FILE USING UTL_FILE
I created using mon_repertoire
create or replace directory mon_repertoire as 'd:\try ';
then I did
GRANT read, write on DIRECTORY mon_repertoire TO scott;
then I create a following procedure d...
Create or replace procedure UTLTEST as
utl_file.file_type F1.
Start
-Open a file in write mode
F1: is utl_file.fopen('MY_DIR','newfile.txt','W');.
-Write a line to a file
UTL_FILE.put_line (f1, 1.) "This is a test of package UTL_FILE);
UTL_FILE.put_line (f1 2), Oracle has added a new procedure in the package ');
UTL_FILE.put_line (f1 3), Let's see together the procedure one ');
-Closes a file
UTL_FILE.fclose (F1);
end;
I got the following errors:
ERROR on line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS." UTL_FILE", line 475
ORA-29283: invalid file operation
ORA-06512: at "SCOTT. UTLTEST', line 5
ORA-06512: at line 1
How can I do this task?Hello
Create an inventory of items that points to a physical directory on the server.
If the path to the physical directory in the db server is D:\applications
Then,
Simply create the directory as objectCREATE or replace directory mon_repertoire is "D:\applications";
Then try your coding plsql.
-
Create the HTML using UTL_FILE
I'll send emails using UTL_MAIL, sending the HTML, I generate dynamically to a cursor and the text with UTL_MAIL sending. SEND_ATTACH_VARCHAR2.
When I get these emails, some periods are missing some very important numbers.
I decided to record this HTML code in my server and then send it using UTL_MAIL. SEND_ATTACH_RAW.
How can I create this HTML using UTL_FILE file and save it to a folder on my server. After you send the message, I would like to delete this file.
I already have my HTML code and just want to save it as a HTML file.First create a virtual directory of the Oracle who can access the path specified in your server. Make sure that your procedure have write access to this directory.
then in your code, you create something like this
IE - myFileName 'ABCD.html' +.
myDIR - IE 'YourOracleVirtualDir ' +.CREATE OR REPLACE PROCEDURE CREATE_HTML
(myFileName IN VARCHAR2, myDir IN VARCHAR2) ASv_cFile UTL_FILE. TYPE_DE_FICHIER;
v_cDir VARCHAR2 (30): = myDir.
v_cExcept EXCEPTION;BEGIN
v_cFile: = UTL_FILE. FOPEN (v_cDir, myFileName, 'W');
UTL_FILE. PUT(v_cFile,e)'|| Chr (13) | Chr (10));
UTL_FILE. PUT (v_cFile, "It's your HTML Code" |) Chr (13) | Chr (10));
UTL_FILE. PUT(v_cFile,e)'|| Chr (13) | Chr (10));
UTL_FILE. FCLOSE (v_cFile);EXCEPTION
WHILE OTHERS THEN
UTL_FILE. FCLOSE (v_cFile);
RAISE_APPLICATION_ERROR (-20010, SQLERRM);END;
to remove the file, you can use
UTL_FILE. FREMOVE (myDir, myFileName);
Published by: lie Ching Te on January 20, 2010 07:53
-
How to send other linguistic data to the server using Http
Hello
How can I send data to the server except English other languages how to send to the server. Please someone help me it's urgent.
Thank you
Kind regards
Bharath kumar
Peter cool.
problem fixed
I use postdata String = new String (textField.getText (.getBytes("UTF-8")));
Thank you
-
How to add data to the table using Manager POST for restful Apex application
Hi all
I managed to create a service application web Manager restful using GET for the Restful service module. I am able to get the data in row on the presentation of a table row id in the application. But I can't find an appropriate example, how the new data in the table can be posted or deleted. I created a POST handler for a URI scheme and look forward on how to proceed. Any help would be really appreciated.
Source for the POST Manager:
Start
insert into ALL_BOOKS values(:id,:book);
end;
Also created 2 parameters id and the book.
Hi jerry2134,
jerry2134 wrote:
I managed to create a service application web Manager restful using GET for the Restful service module. I am able to get the data in row on the presentation of a table row id in the application. But I can't find an appropriate example, how the new data in the table can be posted or deleted. I created a POST handler for a URI scheme and look forward on how to proceed. Any help would be really appreciated.
Source for the POST Manager:
Start
insert into ALL_BOOKS values(:id,:book);
end;
Also created 2 parameters id and the book.
Check out the following tutorials OBE, that explains the creation of GET and POST RESTful Web Services and how to use them in the APEX.
- Creation and use of RESTful Web application services Express 4.2
- Creation and use of RESTful Web application services Express 5.0
Also what yo mean "looking forward on how to proceed? Do you want to or created for use/consume in your Oracle APEX application hosted RESTful web services?
If Yes, in your Application, you must create a RESTful Web Service reference -> shared components. Then, create a form/report based on Web Service reference.
Kind regards
Kiran
-
How to access the Non-space data of the object using the API of the HTML5
Using the Oracle cards HTML5 API, is it possible to access the data an excerpt when generating a map?
For example, my database has a table named ITEMS:
Table: ELEMENTS
COL_A
COL_B
COL_C
COL_D
COL_E
COL_F
GEOMETRY
This table contains a number of objects point. With the help of Mapviewer, I can successfully create a map by using the HTML5 API. Here is an example of how I used the constructor 'OM.layer.VectorLayer.TYPE_JDBC' to retrieve the objects point of my database.
pointLayer = new OM.layer.VectorLayer ("PointLayer",
{
infoWindow: true,
def:
{
type: OM.layer.VectorLayer.TYPE_JDBC,.
dataSource: "myDatabase",.
SQL: "SELECT * FROM POINT."
geometryColumn: "GEOMETRY."
labelColumn: "COL_A."
loadOnDemand: false,
URL: baseURL
},
renderingStyle: circleMarker
});
How can I use the HTML5 API to access the data in the other columns (COL_A, COL_B, etc.) of my table?
I know that the methods DisplayInfoWindow() and displayTabbedInfoWindow of the Map class to view this information by clicking on a specific point on the map. But I would like to have access to all the points to create a table below my map showing all points (and their data) shown on the map.
Hello
You can try this code:
functions var = pointLayer.getAllFeatures ();
for (var i = 0; i)
{
Features [i]. GetAttributes() ["COL_A"];
Features [i]. GetAttributes() ["COL_B"];
......
}
-
Reading file and dump the data into the database using BPEL process
I have to read the CSV file and insert data into the database... To do this, I created some asynchronous bpel process. Adapter filed added and associated with the receive activity... Adapter DB has added and associated with the Invoke activity. Receive two total activity are available in the process when trying to Test em, receive only the first activity is complete and awaits the second receive activity. Please suggest how to proceed with...
Thanks, Maury.
Hi Maury,
There is no need in step 2 that u mentioned above. I donot find useless a webservice?
The process will be launched by the CSV file, then using the processing activity, you can put it in the DB.
There should be no way where you can manually test it by giving an entry. All you can do to test is to put the file in the folder you mentioned when configuring the file adapter.
You just need to have the composite as below:
ReadCSVFile---> BPEL--> DB adapter
And in your BPEL process:
Recieve--> Transformation activity--> call activity
Try to work on some samples listed on the oracle site and go through the below URL:
The playback of the file adapter feature using
Thank you
Deepak.
-
Pump data to the directory import
Hello!!!
I have a slight problem with datapump. I try to import a complete database of an export that I copied to a new server.
Windows Server 2003 R2 SP2 64-bit and EE Oracle 10.2.0.4
I run this:
Impdp system/dacnai directory is dumpfile 'Z:\backup\Backup_Docark' = DOCARK_FULL. DMP logfile = IMP_FULL.log full = y
But it does not work. It does not recognize the directory (I also tried without the '). What I am doing wrong? I can't do it!
Thank you!
Looks like you should use impdp NETWORK_LINK clause.
In doing so, you import the network and don't need a dump of the file at all.
------------
Sybrand Bakker
Senior Oracle DBA
-
Build the value of 100 mb of data in the table using the loop
DB version: 11.2
How can I create about 100 MB of test data in a table using minum number of records.
If I use the below for loop. It takes 100,000 records to fill only 2 MB.
SQL> create table a2 (mynum1 number, mynum2 number); Table created. begin for i in 1..100000 loop insert into a2 values(i,i*2); end loop; end; select segment_name, bytes/1024/1024 MB from dba_segments where segment_name = 'A2' AND owner='SCOTT' SEGMENT BYTES/1024/1024 -------- --------------- A2 2
Hello
Is that what you are looking for?
SQL> CREATE TABLE tbl1(c1 CHAR(1024)); -- ~1KB per row Table created. Elapsed: 00:00:00.00 SQL> INSERT /*+ APPEND */ INTO tbl1 SELECT 'X' FROM dual CONNECT BY LEVEL < 100000; -- 100K rows * 1KB = 100MB + some additional overhead 99999 rows created. Elapsed: 00:00:13.02 SQL> SELECT bytes/1024/1024 MB FROM user_segments WHERE segment_name = 'TBL1'; MB ---------- 113.75
Lukasz
-
moved the file data, but the space used is always the same.
Hi due to some problems of space I took the offline tablespace, then move the file to a location different and introduced the online storage space after renaming. After all this, the space used for the file system is always the same. How can I get the space freed up?Hello
I'd be willing to bet that a core oracle process holds the lock (e.g. dbwr). use lsof (open list) command on each one and you should get the info or perhaps fuser.
Paul
Maybe you are looking for
-
How to do old curiosity Stream on my Apple TV?
How to do old curiosity Stream on my Apple TV?
-
Touchpad on Satellite A200-1 body weight does not light when you tapoterez the top right
Satellite A200-1 body weight. This has a double Synaptics touchpad mode that switches modes when you press on the upper right corner - at least he used to. Upgraded to Win7 and had to do a clean install as I had Vista Ultimate 32 bit version.Used the
-
Any new idea to do this? No app that would work?
-
Register of config data error (LV RT 8.2.1)
Hello I get an error #1 (I realize is a universal code) on the Registry.vi of configuration data: invalid object 0 when I try to open a configuration file. We wrote our own program that just traverses the NEITHER "reading-open-close" sequence vi, the
-
That is the message in the WINDOW of WIRELESS CONNECTION. I was using internet last night when I turned off computer. Booted up today and the message above is all I get. No internet. Where should I go from here? I tried to fix IT.