Dbms_lob wwv_flow_files
I created a file upload as shown in the how-to, which I am using to upload csv files to the wwv_flow_files table. I would like to take the blob and break it apart for insert to a processing table. However, I am new to dbms_lob and would like any help possible. Are there any good references to using this in a pl/sql package to create inserts from blob fields?
Many Thanks!!!
Ok, I was able to find a solution and I'll post what I have. I was uploading a csv file with 3 fields (number, text, text) to the flow_files table. I was able to break this apart for insert using the anonymous block below. I'll probably store this as a function so that I can return a success/failure message.
I hope this can help someone else!
Begin
Declare
v_blob blob;
v_raw raw(32767);
v_len number;
v_pos integer := 1;
v_amt binary_integer := 15;
v_out varchar2(500);
v_sql varchar2(255);
v_search raw(4);
l_linebreak varchar2(2) := chr(13)||chr(10);
v_pad1 varchar2(5);
v_pad2 varchar2(7);
v_pad3 varchar2(5);
begin
v_sql := 'insert into table_x (field1,field2,field3) values ';
v_search := utl_raw.cast_to_raw(l_linebreak);
select BLOB_CONTENT
into v_blob
from WWV_FLOW_FILE_OBJECTS$
where id = 775113501593078;
v_pad1 := ','||'''';
v_pad2 := ''''||','||'''';
v_pad3 := ''''||')';
v_pos := 1;
loop
v_amt := DBMS_LOB.INSTR(v_blob,v_search,v_pos);
v_amt := v_amt - v_pos;
If v_amt < 1 then
v_amt := 1;
End if;
/* Read current sector from blob into raw*/
DBMS_LOB.READ(v_blob,v_amt,v_pos,v_raw);
v_out := utl_raw.cast_to_varchar2(v_raw); --convert raw to varchar2 and set to output variable
--dbms_output.put_line(v_out);
v_out := replace(v_out,chr(10),'');
v_out := replace(v_out,chr(13),'');
If length(v_out) > 0 then
v_out := v_sql||'('||replace(substr(v_out,1,instr(v_out,',')),',',v_pad1)
||replace(substr(v_out,instr(v_out,',')+1,(length(v_out)-(instr(v_out,',')))),',',v_pad2)
||v_pad3;
--dbms_output.put_line(v_out);
Execute immediate v_out;
End if;
v_out := null;
v_raw := null;
v_pos := v_pos + v_amt +1;
v_amt := null;
end loop;
EXCEPTION
WHEN others THEN
dbms_output.put_line(sqlerrm);
NULL;
end;
end;
Similar Messages
-
How to get all image files from a folder to wwv_flow_files?
Hi there!
Is it possible in apex to show, in a report look-a-like, all image filenames from a folder in another machine (i enter in that machine by ip) and insert all files into wwv_flow_files?
I want to see all files, then pick one and open a image...
But it can't be by browse item... it has to show all filenames as a list...
If it is possible, how can i do it?
Thanks!
Best regards,
Luis PiresHi,
you can connect to the server using UTL_HTTP.
Then for each files you copy the response into a BLOB to be able to show it or to store it in a table.
A piece of code :
begin
-- initialize the BLOB.
dbms_lob.createtemporary(l_blob, false);
-- path to the file
l_url := 'http://your_server/your_file.jpg';
-- begin retrieving the target.
l_req := utl_http.begin_request(l_url);
-- identify ourselves (some sites serve special pages for particular browsers)
utl_http.set_header(l_req, 'User-Agent', 'Mozilla/4.0');
-- start receiving the response.
l_resp := utl_http.get_response(l_req);
-- copy the response into the BLOB.
begin
loop
utl_http.read_raw(l_resp, l_raw, 32767);
dbms_lob.writeappend (l_blob, utl_raw.length(l_raw), l_raw);
end loop;
-- stop when exception end_of_body is raised
exception
when utl_http.end_of_body then
utl_http.end_response(l_resp);
end;
end;It's a minimal example, you may need authentication, check l_resp.status_code, etc... -
Download pdf into browser, object not stored in wwv_flow_files
Was wondering if you’re able to help? I want to view a pdf I’ve stored in a blob column via APEX.
I can view pdf’s I’ve uploaded and stored via apex i.e. stored in wwv_flow_files, but not objects stored in other tables.
To help see what I’m doing I will detail the way I can get working (Via Apex)
Scenario via apex:
create table demo.apex_document_upload(
name varchar2(90),
load_date date,
load_user varchar2(100));
Create upload page
Using a HTML region
I insert a button called upload with a branch to page of &APP_PAGE_ID.
Create a file browse item
Add a page process plsql to run on upload button
begin
insert into demo.apex_document_upload (name,load_date,load_user )
values (:P9_FILE_NAME,sysdate, :app_user);
end;
Run page and upload a pdf document.
Create PDF Apex View page
Create a reports page using below sql code.
select
wff.id, lf.load_date, lf.load_user, wff.filename PDF_FILE
from
wwv_flow_files wff, demo.apex_document_upload lf
where
wff.name = lf.name;
Edit the report attributes and go into the pdf_file link attributes:
Set
link text = #PDF_FILE#
target=URL
url=p?n=#ID#&p_inline=YES
Run the report page click on the link and the pdf should be launched.
Issue
Issue I want to store the images in the user’s schema and load the images in bulk, I have over 100,000 pdfs to load and do not want to do this one at a time.
I can load the images into Oracle OK using below:
The issue with this is that the blob is stored in the wwv_flow_files table and you have to laod one image at a time. I’m looking at loading on 100k of images so this is not practical.
So I was wanting to load the images via sqlldr
create table demo.schema_document_upload
name varchar2(100),
file_name varchar2(100),
file_image blob,
load_date date)
sqlldr controlfile
load_bulk_pdf.ctl
load data
infile *
append
into table demo.schema_document_upload
FIELDS TERMINATED BY ','
Name CHAR
, file_name CHAR
, file_image LOBFILE(file_name)
TERMINATED BY EOF
NULLIF file_name='NONE'
, load_date SYSDATE
begindata
image1,00000002.pdf
image2, 00000006.pdf
image_3,0000000A.pdf
This loads the PDF’s into the demo.schema_document_upload table, but I’ve been unable to get APEX to open these PDF’s.
Has anyone tried this before?Hello dtt676 (Tip for you, put your name in your profile) :-)
Here's how I do it...
1)Create a stored procedure (Standalone or as a part of a package as appropriate) like this...
PROCEDURE get_pdf (p_pdf_id IN NUMBER) IS
v_blob BLOB;
l_length NUMBER;
v_mime_type VARCHAR2(30);
v_file_name VARCHAR2(200);
BEGIN
-- get pdf_data and its mime type from the database
SELECT a.pdf
,a.mimetype
,a.filename
INTO v_blob
,v_mime_type
,v_file_name
FROM pdf_table a
WHERE a.pdf_id = p_pdf_id;
l_length := dbms_lob.getlength(v_blob);
owa_util.mime_header(v_mime_type, FALSE);
htp.p('Content-length: ' || l_length);
htp.p('Content-Disposition: filename="' || v_file_name || '"');
owa_util.http_header_close;
wpg_docload.download_file(v_blob);
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001, 'Error: ' || SQLERRM
||'. p_pdf_id: ' || p_pdf_id
END get_pdf;2) In "Shared Components", create an "Application Process" of type "On Demand" type "PL/SQL Anonymous Block" called GET_PDF with the following 'Source'
BEGIN
get_pdf(p_pdf_id => &P1_PDF_ID.);
END;3) Make sure your target page for displaying your PDF has an item containing the unique ID of the stored PDF you want to display, an item containing the mimetype and an item containing the filename.
4) create an HTML Region on the page you want to display your PDF with the following in the region source.
<iframe src="f?p=&APP_ID.:1:&APP_SESSION.:APPLICATION_PROCESS=GET_PDF" width="800" height="1000" name="&P1_FILENAME." type="&P1_MIMETYPE."></iframe>You will need to set the page IDs to the relevant page for your application and you'll need to set the item names to those you're using in your database but, assuming you have your PDFs stored in a BLOB column, this should do the trick.
Please feel free to come back to me if you have any questions.
Kind regards
Simon Gadd -
Whose files do I see in wwv_flow_files.
Hi,
I wish to download and run a piece of vbscript in the users environment. The vbscript does a mail merge with word, dowloading the mail recipients through a URL that I provide.
Using the upload/download tutorial I have created my own procedure to download a file which I have uploaded.
The procedure goes like this:
create or replace procedure run_vbscript
as
v_length number;
v_file_content blob;
v_blob blob;
v_clob clob;
v_errmsg varchar2(100);
begin
begin
select blob_content
into v_file_content
from wwv_flow_files
where filename = 'labels.vbs';
exception
when others then
v_errmsg:= substr(sqlerrm(-sqlcode),1,100);
DBMS_LOB.CREATETEMPORARY(v_file_content, true, DBMS_LOB.SESSION);
dbms_lob.writeAppend(v_file_content, length(v_errmsg), utl_raw.cast_to_raw(v_errmsg));
end;
-- set up http header
-- use an nvl around the mime type and
-- if it is a null set it to application/octect
-- application/octect may launch a download window from windows
owa_util.mime_header('text/vbscript', false);
-- set the size so the browser knows how much to download
v_clob := to_clob('Dim sServer' || chr(10) || ' sServer = "http://<link to xml generating page>"');
v_blob := wwv_flow_utilities.clob_to_blob(v_clob);
dbms_lob.append(v_blob, v_file_content);
v_length := dbms_lob.getlength(v_blob);
htp.p('content-length: ' || v_length);
-- the filename will be used by the browser if the users does a save as
htp.p('content-disposition: attachment; filename="labels.vbs"');
-- close the headers
owa_util.http_header_close;
-- download the blob
wpg_docload.download_file(v_blob);
end run_vbscript;
grant execute on run_vbscript to public
The tricky thing is that when I run this procedure in the SQL Workshop, I get the contents of my uploaded file. When I invoke it from a URL where the URL is #OWNER#.run_vbscript, the procedure executes but the file contents is replaced by the error message "No data found".
Replacing "where filename = 'labels.vbs'" with "where rownum < 2" will provide me with a file from a completely different user.
What is the reason, and what is the best solution?
Thanks in advance,
TorbenTorben - The wwv_flow_files view shows you documents in the documents table (defined in the DAD) that are associated with the workspace to which you a currently authenticated. This is the workspace you logged into for SQL Workshop, or the workspace associated with the APEX application that is running your query against the view. If you run the procedure through the URL directly, you are not authenticated so you don't see any rows (except a few orphaned documents).
If you upload files and transfer them to your own table, then you could download from your table, implementing whatever security measures you deem appropriate.
Scott -
Full path and filename in wwv_flow_files after upload from UNC path in IE
I have a page with a file browse item. After page submit I move the file from wwv_flow_files to another table.
Normally the column wwv_flow_files.filename only contains the filename. However, when using IE9 and selecting a file from an UNC path the column contains the full path+filename.
Does anybody have an idea what happens here?
How can I make sure I only get the filename?
Using Apex 4.02.007
Edited by: Rene W. on Feb 28, 2013 6:39 AMRene W. wrote:
I have a page with a file browse item. After page submit I move the file from wwv_flow_files to another table.
Normally the column wwv_flow_files.filename only contains the filename. However, when using IE9 and selecting a file from an UNC path the column contains the full path+filename.
Does anybody have an idea what happens here?
How can I make sure I only get the filename?For security/privacy reasons recent versions of browsers by default do not send local file path information from File Browse items to the server, nor expose the file path in the control's JavaScript methods. Firefox, Safari and Chrome only provide the filename. IE6 & IE7 still yield the path in Windows format. IE8+ and Opera have adopted an irritating approach of replacing the path with a wholly imaginary "C:\fakepath\"—and this monstrosity has sadly had to be enshrined in the HTML spec. A reasonably compatible way to strip the path in JS is provided there, or you should be able to do it fairly easily in PL/SQL when moving the file.
The fact you are getting the full path suggests that the IE security config setting "Include local directory path when uploading files" (or IE9 equivalent) is used in your browser/environment to enable the path to be exposed in IE. This may be necessary to support dismal legacy applications. Consult whoever is responsible for browser security configuration at your site to see why/if this setting is necessary. -
Error in using DBMS_LOB Package
Hi,
I am attaching a PDF File through a database procedure as shown below
create or replace procedure load_document(document_id in number, filename IN varchar2, doc_desc IN VARCHAR2, doc_type IN VARCHAR2) as
f_lob bfile;
b_lob blob;
--document_name varchar2(30);
--mime_type varchar2(30);
document_name oea_documents.document_name%TYPE;
mime_type oea_documents.document_mime_type%TYPE;
dot_pos number;
v_file_type VARCHAR2(10);
begin
-- Find the position of the dot ('.') located in the filename
dot_pos := instr(filename,'.');
-- Get the filename without extension and use it as image name
document_name := substr(filename,1,dot_pos-1);
-- Build the mime type . Retrieve the file extension and add it to 'image/'
v_file_type := SUBSTR( filename, dot_pos+1, Length(Filename) );
IF ( UPPER(v_file_type) IN ('JPG','JPEG','TIF','TIFF','GIF') ) THEN
mime_type := 'image/'||substr( filename , dot_pos+1 , length(filename) );
ELSIF ( UPPER(v_file_type) = 'PDF' ) THEN
mime_type := 'application/pdf';
ELSIF ( UPPER(v_file_type) = 'DOC' )THEN
mime_type := 'application/msword';
ELSIF ( UPPER( v_file_type) = 'XLS') THEN
mime_type := 'application/ms-excel';
ELSE
mime_type := 'image/'||substr( filename , dot_pos+1 , length(filename) );
END IF;
insert into oea_documents (document_id,
document_name,
document_mime_type,
document,
document_description,
document_type
values(document_id, document_name, mime_type, empty_blob(),doc_desc,doc_type) return document into b_lob;
-- /!\ Directory name has to be UpperCase !
f_lob := bfilename('FILE_LOAD',filename);
o_dset_test('5');
dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
o_dset_test('6');
dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob) );
dbms_lob.fileclose(f_lob);
commit;
end;
FILE_LOAD is a folder on the database server(unix).
I have also tried to give the full path on the unix databse server instead of FILE_LOAD directory but then it gives error ora-22285.
while executing this procedure I am getting the error ora-22288(Invalid file or directory).
But this occurs randomly
For instance i tried to attach a pdf file with the name cross.pdf ,it gave me the above error and when i renamed the file as Cross.pdf it attached successfully.
The error comes whilke executing the statement dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
Please guide on the above issue.Hi,
Welcome to the forum!
user1356624 wrote:
f_lob := bfilename('FILE_LOAD',filename);
FILE_LOAD is a folder on the database server(unix).
I have also tried to give the full path on the unix databse server instead of FILE_LOAD directory but then it gives error ora-22285.The first argument to BFILENAME is the name of a directory object, as found in the directory_name column of all_directories. That is not the same thing as a folder name, which is found in the directory_path column of all_directories. Look up [CREATE DIRECTORY|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_5007.htm#sthref6211] in the SQL Language manual for a description of Oracle's directory objects.
If you have problems with this, post the results of
SELECT *
FROM all_directories;It might also be useful to see the Oracle "CREATE DIRECTORY" command that was used.
As you probably noticed, this site compresses white space by default.
When you post code or results on this site, type these 6 characters:
(small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
Edited by: Frank Kulash on Aug 10, 2009 3:35 PM
Added link. -
Uploading multiple files into wwv_flow_files.
Hi,
I've been happily using the apex file browse button functionality to upload files into the wwv_flow_files table and moving them over to my app specific tables for some time now.
I was wondering; Is there a straight forward way of uploading all the files in a specified folder into the wwv_flow_files table in a single process; Rather than having to upload them one at a time?
Cheers,
Yog.Ok. I've tried creating a new DAD by following the instructions here:
http://www.oracle-base.com/articles/10g/FileUploadDownloadProcedures10g.php
I've tried various combinations but my lack of experience is letting me down I think.
I may not even be on the right tack.
I'm trying to upload a file to a databse table through some kind of automated process. i.e. bypassing the need for a filebrowse button. Ideally I'd like to be able to pass in a filepath to a procedure and for the file to be uploaded.
Can anyone help with this???
Getting desperate.
Yog -
Need help in using dbms_lob.read
I need to upload a file into an Oracle table into a Blob column. The file name along with the file contents are all in one BLOB column.
Once that is done I need to read from the file and extract the file contents and load it into a staging table.
File being uploaded is a *.CSV* file.
E.g. Of the .CSV file is: ABC.csv file and its contents will look like:
1,Hello,Nisha
2,Hi,Ravi
3,Bye, Rahul
Etc…..
Therefore the table containing the BLOB column will contain:
File Creation_date
ABC.csv 09/11/2009
How can I read a file from the BLOB column and upload into a staging table?
Final Staging table should look like:
Record Number Greet Name
1 Hello Nisha
2 Hi Ravi
3 Bye Rahul
I think I am suppose to use dbms_lob.read, but I am not really sure how to use it. If there is any script, kindly mail me the same.
Thanks....Nisha,
Check this example (test) and see if it can be any help. I have utl_file and sqlldr
First Method -- I loaded alert.log successfully and you can imagine how big this file can be (5MB in my test case)
create table t1clob
( clob_text clob);
CREATE OR REPLACE DIRECTORY DIR AS '/path_to_csv_file/;
DECLARE
clob_data CLOB;
clob_file BFILE;
BEGIN
INSERT INTO t1clob
VALUES (EMPTY_CLOB ())
RETURNING clob_text INTO clob_data;
clob_file := BFILENAME ('DIR', ABC.csv');
DBMS_LOB.fileopen (clob_file);
DBMS_LOB.loadfromfile (clob_data,
clob_file,
DBMS_LOB.getlength (clob_file)
DBMS_LOB.fileclose (clob_file);
COMMIT;
END;Second Method: Use of Sqlldr
Example of controlfile
LOAD DATA
INFILE alert.log "STR '|\n'"
REPLACE INTO table t1clob
clob_text char(30000000)
)Hope this helps. -
No Data Found Error in wwv_flow_files
Hello All,
I have written a procedure to upload the .csv file data into one of my database Table. It was working fine some days back, but when I try to upload a .csv today, it gives me error "No Data Found".
This is the Query I am using to fetch the data from wwv_flow_files table:
select blob_content into v_blob_data
from wwv_flow_files
where last_updated = (select max(last_updated) from wwv_flow_files where UPDATED_BY = UPPER(:APP_USER))
and id = (select max(id) from wwv_flow_files where updated_by = UPPER(:APP_USER));
this is returning No data found error.
Please suggest what is the problem.
Apex vesion : 4.0.1.00.03
DB: 11g
Thanks
TauceefHi Trent,
As I said, I am using this code from a long time ago, it was working fine before and I have uploaded many files using this code.
But suddenly I don't know what happen it start giving this error.
For making sure that this statement is the one which is giving "no data found" error I commented all the other select statements
and I still got no data found. So it's confirmed.
One more thing, I tried to run this code in SQL command by hard coding the :APP_USER value and this is what I got in the result:
BLOB_CONTENT
[unsupported data type]
means this code is returning something but at run time it is giving no data found.
Please suggest.
Thanks
Tauceef -
Dump data from a table into wwv_flow_files
HI,
Could you help me, to take data from a table, and insert it into blob_content in wwv_flow_files; and data should be stored in a .txt file
regards,
RajeshAlex Nuijten wrote:
But in case of APEX, that might be a really bad idea to insert metadata in the apex repository:
http://joelkallman.blogspot.com/2010/01/perils-of-modifying-application-express.html
This is not really an APEX metadata table, Alex. As far as I recall, it is a standard mod_plsql documents table that handles file uploads. One can also insert a document into the table dkirectly using an INSERT as it pretty straight forward.
Not exactly sure why though as the doc download procedure needs a LOB or CLOB.. and it does not care from what table you create it from - or whether you do it on the fly.
But still, you make an important point of using application/system objects for the purpose they have been designed for. And in this case, creating your own documents table may be a lot better. -
Error while creating AW using DBMS_LOB with XML..
Hi All,
I am trying to create AW using DBMS_LOB package with XML,
while creating AW,i am facing the following error.find the code also below :
declare
xml_awcreate_clob clob;
xml_awcreate_st varchar2(4000);
begin
DBMS_LOB.CREATETEMPORARY(xml_awcreate_clob,TRUE);
dbms_lob.open(xml_awcreate_clob, DBMS_LOB.LOB_READWRITE);
dbms_lob.writeappend(xml_awcreate_clob, 48, '<?xml version = ''1.0'' encoding = ''UTF-8'' ?>');
dbms_lob.writeappend(xml_awcreate_clob, 43, '');
dbms_lob.writeappend(xml_awcreate_clob, 63, '<AWXML version = ''1.0'' timestamp = ''Mon Feb 11 13:29:11 2002'' >');
dbms_lob.writeappend(xml_awcreate_clob, 15, '<AWXML.content>');
dbms_lob.writeappend(xml_awcreate_clob, 25, ' <Create Id="Action41">');
dbms_lob.writeappend(xml_awcreate_clob, 19, ' <ActiveObject >');
dbms_lob.writeappend(xml_awcreate_clob, 163, ' <AW Name="NEW_XML_AW" LongName="NEW_XML_AW" ShortName="NEW_XML_AW" PluralName="NEW_XML_AW" Id="NEW_XML.AW"/>');
dbms_lob.writeappend(xml_awcreate_clob, 19, ' </ActiveObject>');
dbms_lob.writeappend(xml_awcreate_clob, 11, ' </Create>');
dbms_lob.writeappend(xml_awcreate_clob, 16, '</AWXML.content>');
dbms_lob.writeappend(xml_awcreate_clob, 8, '</AWXML>');
dbms_lob.close(xml_awcreate_clob);
xml_awcreate_st := sys.interactionExecute(xml_awcreate_clob);
end;
ORA-21560: argument 2 is null, invalid, or out of range
ORA-06512: at "SYS.DBMS_LOB", line 833
ORA-06512: at line 12
Any idea or thought on this would be appreciable.
Thanks in advance.
AnwarDid you change any of the text in the lob write statements ?
I believe you get this error if you increase the number of characters without increasing the 1st argument which looks as though it represents the number of characters -
Error while converting CLOB to varchar using DBMS_LOB.SUBSTR() in Oracle11g
Hi
Whenever I am using DBMS_LOB.SUBSTR(columnname,4000,1) package for a clob column in a simple Select Query, the following error is thrown for Oracle 11g version.
ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1.
Please find the installation details of the database and the character set
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET AL32UTF8
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.1.0
It is working fine if I reduce from 4000 to 3500 . But I want to use 4000.
Please let me know if any solutionyou are using a multibyte character set:
NLS_CHARACTERSET AL32UTF8
so each character takes between 1 and 4 bytes of storage.
a varchar2(4000) column can only hold 4000 BYTES. Regardless of the character set - varchar2 is limited to 4000 bytes.
In a single byte character set, that is 4000 characters as a character = a byte
In your character set, a varchar2(4000) can hold somewhere between 1000 and 4000 characters - depending on what the characters are.
So, you must have some CLOB whose first 4000 characters include at least one "more than one byte" character. That won't fit into a varchar2(4000)
Your approach of backing off the substr size is reasonable (and you'll need to remember that in your application - end users can type in as little as 1000 characters and get an error about the column being too small!) as it reduces the number of BYTES to be belong 4000. -
DBMS_LOB.fileopen issue : please help
Hi all,
I am not able to open the file name with umlauts using DBMS_LOB.fileopen.
sample file name is Übritäts_6.doc
Can somebody throw some light on this?
thanks
ktWhat is you database version?
What is your database character set?
What is your database server operating system (Note: Unix is case sensitive, Windows is not)
What is your code that is doing this file opening? -
How to insert 10 files from a directory to database,can i use dbms_lob??
Hii
I want to load 10files in my local drive into a table...how to do this.I'm able to do this individually using dbms_lob.loadfromfile and bfil but ,I want to copy all the files i that drive at time to my table...Is there any way to do this..?Okay... Here is some sample code that will help you store the files in binary format into db tables.
create table t_blob(bid integer, blbdata blob);
select * from t_blob;
create or replace directory ext_tab_dir as 'C:\Oracle\ExtTab_Dir';
grant read, write on directory ext_tab_dir to priya;
declare
src_file bfile;
dest_file blob;
len_file pls_integer;
begin
src_file:=bfilename('EXT_TAB_DIR','XML.doc');
insert into t_blob values(1,empty_blob()) returning blbdata into dest_file;
select blbdata into dest_file
from t_blob
where bid=1 for update;
dbms_lob.fileopen(src_file,dbms_lob.file_readonly);
len_file:=dbms_lob.getlength(src_file);
dbms_output.put_line(len_file);
dbms_lob.loadfromfile(dest_file,src_file,len_file);
update t_blob
set blbdata = dest_file
where bid = 1;
dbms_lob.fileclose(src_file);
end;
/I haven't used the wrap utility yet, so not much hands on with it. I guess the wrap utility at the OS level. Not sure if it will work at SQL prompt. -
Managing wwv_flow_files table
Lets say I have a file upload feature on one of my pages.
When the page is submitted, the file is uploaded to the wwv_flow_files table.
I have a after submit process to parse the file, load it into a collection and process the data. When the process ends successfully, it does a DELETE from wwv_flow_files.
I put a validation to upload only certain types of files based on the extension. If the validation fails, the file stays around in the wwv_flow_files table.
If I have a after submit parse routine to parse/validate the file and that fails, the file stays around in the wwv_flow_files table.
If I have any othe error in my after submit process that causes it to exit via my raise_application_error(), the file stays around in the wwv_flow_files table.
In this situation, what is the recommeneded way to properly purge the wwv_flow_files table?
I havent yet put COMMITs anywhere in any of my HTML DB apps because the engine implicitly does a commit at the end of every page view, but this file upload thing seems to be its own little "autonomous transaction".
ThanksVikas - If you can do a delete after your process
runs successfully, why can't you do a delete when you
encounter one of the other situations (before raising
an unhandled exception)? Let me explain all my "use cases".
1. On Submit validation that checks the "extension" of the file. This is a simple PL/SQL expression that checks lower(:P1_FILENAME) like '%.csv'.
If this validation fails, the file hangs around in the wwv_flow_file_objects$ table, how can I prevent this?
2. If the validation succeds, I proceed to my one and only after submit process that does something like
parse_file(:P1_FILENAME);
if something then
raise_application_error(-20000,'something failed');
end if;
if otherthing then
raise_application_error(-20000,'otherthing failed');
end if;The parse_file procedure parses the file and stores it in a collection and if everything succeeds it does a delete from wwv_flow_files where filename=:P1_FILENAME;
How can I make sure that the file doesnt stick around in wwv_flow_files no matter what?
For a catch-all technique that recognizes fringe cases, consider a dbms job
that runs from your workspace.What would this job look like?
Even a rollback in your own page process would be too
late to prevent it. A rollback in your process would
prevent the file from appearing in the wwv_flow_files
view but would not prevent it from remaining in the
underlying wwv_flow_file_objects$ table.Not sure I understand this. The wwv_flow_files is a simple wrapper view FROM wwv_flow_file_objects$
WHERE security_group_id = wwv_flow.get_sgid;So why would something be in the table but not in the view?
Maybe you are looking for
-
We have following scenario: On Import POs say article cost is $100 Import duty is $5 Freight cost is $10 Commission cost is $2 Brokerage Fee is $ 2 Some of these are payable to different vendors and on PO only estimated cposts are identified. Questio
-
i try to build my first servlet file. before i install the file into JWS, i compile the program, but it gave me messages like: "javax.servlet.http does not exist", "javax.servlet does not exist". i installed JavaWebServer properly, but cannot find js
-
I can't download or buy anything from App Store with iPhone 4S.
After updating ti iOS7 App Store haven't been working correctly. No new or old buys or downloads. When I took auto updates off, I cant update because problems with buying/downloading. Error message keeps telling me "*App im trying to buy/download* is
-
Google Translate Unable to generate thumbnail
I have just pasted the code to generate a Google language button into the insert html panel but instead of generating the image of the button on the page it shows a warning?
-
Lookout 4.5 / Windows XP problems
Hi my name is Roger and I am new to this forum, but have been using Lookout for SCADA since it came on floppy. I was asked to replace an aging Win 98 era PC with a faster machine and ran into numerous glitches. I am finding Lookout 4.5 unstable with