Query the content of blobs
Dear all,
I have a table containing blobs with only text in there. Now I would like to query the table for records where the blob contains a certain string. However I keep getting a ORA-00932 error message stating inconsistent datatype; expecting NUMBER got BLOB
This is the query I use where user_data is the BLOB.
select * from user_defined
where user_data like '%test_account_used%'
order by ENQ_TIME desc
Can anybody please explain what is wrong and what is the correct approach on querying a blob.
Hello,
Look at this:
SQL> desc bin_docs
Name Null? Type
DOC_ID NOT NULL NUMBER(5)
NAME VARCHAR2(128)
DOC BLOB
SQL>
Declare
b_lob blob ;
Begin
b_lob := utl_raw.cast_to_raw('One two three yargla oumbala toto' || lpad( 'x', 20000,'x') ) ;
insert into bin_docs values (3, 'xx', b_lob ) ;
End ;
SQL> select doc_id, to_char( substr( utl_raw.cast_to_varchar2(doc), 1, 200 ) )
2 from bin_docs
3 where to_char( substr( utl_raw.cast_to_varchar2(doc), 1, 200 ) ) like '%yargla oumbala%'
4 /
DOC_ID TO_CHAR(SUBSTR(UTL_RAW.CAST_TO_VARCHAR2(DOC),1,200))
3 One two three yargla oumbala totoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SQL> Francois
Similar Messages
-
How to Convert the content in BLOB field into a PDF file...
Hi,
I am having PDF files stored in BLOB column of a table in Oracle Database (11G R2).
I want to retrieve the files back and store them in hard disk. I am successful in storing the content as a file with '.doc' but if I store the file as '.pdf', adobe fails to open the file with error
Adobe Reader could not open file 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)
I am using following example code to achieve my goal...
Declare
b blob;
c clob;
buffer VARCHAR2(32767);
buffer_size CONSTANT BINARY_INTEGER := 32767;
amount BINARY_INTEGER;
offset NUMBER(38);
file_handle UTL_FILE.FILE_TYPE;
begin
select blob_data into b from blobdata where id=1;
c := blob2clob(b);
file_handle := UTL_FILE.FOPEN('BLOB2FILE','my_file.pdf','w',buffer_size);
amount := buffer_size;
offset := 1;
WHILE amount >= buffer_size
LOOP
DBMS_LOB.READ(c,amount,offset,buffer);
-- buffer:=replace(buffer,chr(13),'');
offset := offset + amount;
UTL_FILE.PUT(file_handle,buffer);
UTL_FILE.FFLUSH(file_handle);
END LOOP;
UTL_FILE.FCLOSE(file_handle);
end;
create or replace FUNCTION BLOB2CLOB ( p_blob IN BLOB ) RETURN CLOB
-- typecasts BLOB to CLOB (binary conversion)
IS
|| Purpose : To Convert a BLOB File to CLOB File
|| INPUT : BLOB File
|| OUTPUT : CLOB File
|| History: MB V5.0 24.09.2007 RCMS00318572 Initial version
ln_file_check NUMBER;
ln_file_size NUMBER;
v_text_file CLOB;
v_binary_file BLOB;
v_dest_offset INTEGER := 1;
v_src_offset INTEGER := 1;
v_warning INTEGER;
lv_data CLOB;
ln_length NUMBER;
csid VARCHAR2(100) := DBMS_LOB.DEFAULT_CSID;
V_LANG_CONTEXT NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
BEGIN
DBMS_LOB.createtemporary (v_text_file, TRUE);
SELECT dbms_lob.getlength(p_blob) INTO ln_file_size FROM DUAL;
DBMS_LOB.converttoclob (v_text_file, p_blob, ln_file_size, v_dest_offset, v_src_offset, 0, v_lang_context, v_warning);
SELECT dbms_lob.getlength(v_text_file) INTO ln_length FROM DUAL;
RETURN v_text_file;
END;user755667 wrote:
Hi,
I am having PDF files stored in BLOB column of a table in Oracle Database (11G R2).
I want to retrieve the files back and store them in hard disk. I am successful in storing the content as a file with '.doc' but if I store the file as '.pdf', adobe fails to open the file with error
Adobe Reader could not open file 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)
I am using following example code to achieve my goal...
Declare
b blob;
c clob;
buffer VARCHAR2(32767);
buffer_size CONSTANT BINARY_INTEGER := 32767;
amount BINARY_INTEGER;
offset NUMBER(38);
file_handle UTL_FILE.FILE_TYPE;
begin
select blob_data into b from blobdata where id=1;
c := blob2clob(b);
file_handle := UTL_FILE.FOPEN('BLOB2FILE','my_file.pdf','w',buffer_size);
amount := buffer_size;
offset := 1;
WHILE amount >= buffer_size
LOOP
DBMS_LOB.READ(c,amount,offset,buffer);
-- buffer:=replace(buffer,chr(13),'');
offset := offset + amount;
UTL_FILE.PUT(file_handle,buffer);
UTL_FILE.FFLUSH(file_handle);
END LOOP;
UTL_FILE.FCLOSE(file_handle);
end;
create or replace FUNCTION BLOB2CLOB ( p_blob IN BLOB ) RETURN CLOB
-- typecasts BLOB to CLOB (binary conversion)
IS
|| Purpose : To Convert a BLOB File to CLOB File
|| INPUT : BLOB File
|| OUTPUT : CLOB File
|| History: MB V5.0 24.09.2007 RCMS00318572 Initial version
ln_file_check NUMBER;
ln_file_size NUMBER;
v_text_file CLOB;
v_binary_file BLOB;
v_dest_offset INTEGER := 1;
v_src_offset INTEGER := 1;
v_warning INTEGER;
lv_data CLOB;
ln_length NUMBER;
csid VARCHAR2(100) := DBMS_LOB.DEFAULT_CSID;
V_LANG_CONTEXT NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
BEGIN
DBMS_LOB.createtemporary (v_text_file, TRUE);
SELECT dbms_lob.getlength(p_blob) INTO ln_file_size FROM DUAL;
DBMS_LOB.converttoclob (v_text_file, p_blob, ln_file_size, v_dest_offset, v_src_offset, 0, v_lang_context, v_warning);
SELECT dbms_lob.getlength(v_text_file) INTO ln_length FROM DUAL;
RETURN v_text_file;
END;I skimmed this and stopped reading when i saw the BLOB to CLOB function.
You can't convert binary data into character based data.
So very likely this is your problem. -
To see the content of a BLOB column from sqlplus
Hi,
I have a table which has a BLOB column.
The blobs are text files.
Is there a way to check the content of blob column from sqlplus itself.
Thanks.There's no information about versin of database
If you're using 11g, then refer to this link:
http://dbathoughts.blogspot.com/2008/05/blob-support-in-sqlplus.html
If you're using 10g, then refer to this link
http://www.experts-exchange.com/Database/Oracle/Q_20419597.html
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com -
Change the contents of file.
I have a table with fields BLOB and CLOB.
Store Word files in a BLOB field, my question is:
I change the contents of a Word file stored in a BLOB field using DBMS_LOB.CONVERTTOBLOB?
OR
.-CONVERT THE CONTENT OF BLOB FIELD TO A KIND OF VARIABLE CLOB
2.-CLOB to convert BLOB
3.-load the cam, po BLOB file with the UTL_FILE.
I am l, or correct?
I work with Ortacle Database XE y Apex 3.0.1
Roberto.
Message was edited by:
user584812Please help.
It is getting worse
Adobe flash player is crashing. I already uninstalled and re installed the latest ver. Also it is hanging randomly.
Please help. -
Hi all,
I just started doing the XML Xquery programming in my SQL Server 2012 Management Studio. I executed the following code:
--query the XML Blob using a CTE (pulling from the XML file each time) Products
WITH XmlFile (Contents) AS (
SELECT CONVERT (XML, BulkColumn)
FROM OPENROWSET (BULK 'H:\Products.xml', SINGLE_BLOB) ) AS XmlData
SELECT *
FROM XmlFile
GO
I got the the following Msg:
Msg 491, Level 16, State 1, Line 4
A correlation name must be specified for the bulk rowset in the from clause.
How can I specify the correction name for the bulk rowset in my project?
Please kindly help, advise and respond.
Thanks in advance,
Scott ChangHello Scott,
You have to assign a table alias for the OPENROWSET =>
--query the XML Blob using a CTE (pulling from the XML file each time) Products
WITH XmlFile (Contents) AS (
SELECT CONVERT (XML, BulkColumn)
FROM OPENROWSET (BULK 'H:\Products.xml', SINGLE_BLOB) AS MyXML ) AS XmlData
SELECT *
FROM XmlFile
GO
Olaf Helper
[ Blog] [ Xing] [ MVP] -
How to read the content of a blob col along with other cols as pipe delimit
Hi,
I would like to read the blob content along with the other columns . Assume table TAB1 has columns Response_log, Empcode and Ename. Here Response_log col is a blob data type, and the content of the blob is an xml file.Now i would like to read the content of the xml file of response_log column along with Empcode and Ename as pipe delimited . or else the best option would be to write to a text file with name extract.txt with the data being pipe delimited .
create table tab1(
response_log blob,
empcode number,
ename varchar2(50 byte)
)Sample code goes something like the one below .
select xmltype( response_log, nls_charset_id( 'char_cs' ) ).getclobval() || '|' || empcode || '|' || ename
from tab1 Can I have any other alternate way for this.
Please adviceJust Now one example is given in HOW TO WRITE ,SAVE A FILE IN BLOB COLUMN
-
How To Print the contents of a BLOB Column on a report?(Word Document)
Requirement: The word document will be inserted in a BLOB Column and the data in the word document has to be shown on the reports or the user should be able to see the word document (atleast he should be able to view the contents)?
The data is getting loaded in the database but not sure how to proceed further.
Any inputs on how to proceed will be appreciated.
Thanks.in JComponent there is a method called print(Graphics g)
you can use that with a Printable class
read bout the java.print package in the java doc -
Can you print the contents of a blob in Bi Publisher
For example, Bi Publisher generate a pdf file in apex that will print the contents of a blob.
Let's say you have a record with test.xls in a blob, can I take the test.xls out of the record and have bi publisher print it.
Thanks,
DougBI Publisher can add some blobs to a report, such as a .jpg / .gif / .png, but excel just doesn't make sense, nor do I think it would work.
Tyler Muth
http://tylermuth.wordpress.com
"Applied Oracle Security: Developing Secure Database and Middleware Environments": http://sn.im/aos.book -
How to display the content of a BLOB column in a ADF/BC pages ?
How to display the content of a BLOB column in a ADF/BC pages ?
There is some image in database table blog column. And we want to display image on the screeen.
There is some example about upload and dowload blog columns.
(steve not yet document example page etc...)
But We want to display blog picture in a image component...
is there any basic way to do it ?
Thanks a lot...Ali,
You could just download the sample app... but... here is the servlet code from the demo (look at it just for technique - you'll obviously have to change it for your needs)...
John
package oracle.fodemo.storefront.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.*;
import javax.servlet.http.*;
import oracle.jbo.ApplicationModule;
import oracle.jbo.Key;
import oracle.jbo.Row;
import oracle.jbo.ViewObject;
import oracle.jbo.client.Configuration;
import oracle.jbo.domain.BlobDomain;
import oracle.jbo.domain.DBSequence;
import oracle.jbo.domain.Number;
import oracle.jbo.server.ViewObjectImpl;
public class ImageServlet
extends HttpServlet
private static final String CONTENT_TYPE =
"image/jpg; charset=windows-1252";
public void init(ServletConfig config)
throws ServletException
super.init(config);
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
response.setContentType(CONTENT_TYPE);
response.setContentType(CONTENT_TYPE);
String detailProductId = request.getParameter("detail");
String thumbnailProductId = request.getParameter("thumbnail");
boolean thumbnail = true;
String productId = null;
OutputStream os = response.getOutputStream();
String amDef = "oracle.fodemo.storefront.store.service.StoreServiceAM";
String config = "StoreServiceAMLocal";
ApplicationModule am =
Configuration.createRootApplicationModule(amDef, config);
ViewObjectImpl vo =
(ViewObjectImpl) am.findViewObject("ProductImages"); // get view object (the same as used in the table)
if (detailProductId != null)
productId = detailProductId;
thumbnail = false;
else
productId = thumbnailProductId;
vo.defineNamedWhereClauseParam("paramThumbnail", null, null);
vo.defineNamedWhereClauseParam("paramProductId", null, null);
vo.setWhereClause("DEFAULT_VIEW_FLAG = :paramThumbnail AND PRODUCT_ID = :paramProductId");
vo.setNamedWhereClauseParam("paramThumbnail", (thumbnail? "Y": "N"));
vo.setNamedWhereClauseParam("paramProductId", productId);
vo.executeQuery();
Row product = vo.first();
BlobDomain image = (BlobDomain) product.getAttribute("Image");
InputStream is = image.getInputStream();
// copy blob to output
byte[] buffer = new byte[10 * 1024];
int nread;
while ((nread = is.read(buffer)) != -1)
os.write(buffer, 0, nread);
os.close();
vo.setWhereClause(null);
vo.removeNamedWhereClauseParam("paramProductId");
vo.removeNamedWhereClauseParam("paramThumbnail");
Configuration.releaseRootApplicationModule(am, false);
} -
Reading a Blob (CSV file) and displaying the contents
Hello Experts,
I’m currently working on a system that allows the users to upload an Excel spreadsheet (.xls) in the system. The upload page is a PL/SQL cartridge. Then I’ve written a Java servlet (using Oracle Clean Content) to convert the XLS into a CSV and store it back in the database. (it is stored in the “uploaded_files” table as a blob). I’m trying to create another procedure to read the contents of the blob and display a preview of the data on the screen (using an html table (will be done using cartridge)). After the preview, the user can choose to submit the data into the database into the “detail_records” table or simply discard everything.
Can anyone provide me any guidelines and/or code samples for reading the contents of a blob and displaying it as an html table? My data contains about 10 rows and 20 columns in the spreadsheet. I’ve been looking into using associative arrays or nested tables but I’m getting confused about how to implement them in my situation.
Any help is greatly appreciated.BluShadow,
Thanks for your response. The reason that it is a blob is that we use the same table for uploaded files for several applications. Some files are text, some excel, some other formats. Hence the table has been set up in a generic sense.
However, in my procedure, I'm using
DBMS_LOB.createtemporary and
DBMS_LOB.converttoclob
Is there any way you could possibly provide an example of how to read the contents of the file? -
How to execute the content of varchar variable like a simple query
Hi everyone!
I did a PL/SQL region in apex, in this region I did the query which is storaged in a variable; it was did it concatenate several times,
in the procedure I have several sentences.
I thought that the command 'execute immediate' would get a good result but it do not print the result.
declare
variable varchar2(1000);
begin
--sentences
--execute inmmediate( variable );
--return variable
end;
I only want to how to execute the content of varchar variable.
For example, suppose that the result of this procedure is
'SELECT SYSDATE FROM DUAL'
How and what do I must do for this query execute like a normal query that is in apex?
I expect your prompt reply.
Thank you for your help.
Best regardsLet us say your table containing SQL is
t_sql_table
and has two columns
primary_key
and
sql_query.
You would need to do the following:
1. Create a Report of type "Function returning SQL Query"
2. Put the following there:
DECLARE
v_query VARCHAR2 (4000);
BEGIN
SELECT sql_query
INTO v_query
FROM t_sql_table
WHERE primary_key = 1;
RETURN v_query;
END;Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
Query to get the contents of the package body
What is the query that can be used to get the contents of the package body?
SELECT LINE FROM ALL_SOURCE WHERE TEXT LIKE '%<search_criteria>%'; ???
SQL> SELECT LINE FROM ALL_SOURCE WHERE TEXT LIKE '%dbms_output%';
LINE
166
168
170
173
174
176
178
180
1
23
24
28
44
52
82
... -
Rendering the content of a blob from discoverer
Hi Gurus,
I've got to render, on the web browser, the contents of a blob stored in a table. I don't know, at design time, the type/mime of the blob's content, It's actually stored aside the blob in another column of the same table.
It could be sufficent, for me, presenting a link and asking the user to click on it.
What's the way I can realize this?
Thanks in advance
Norberto
PS: My skill is mainly on forms/reports... I'm not an ace in Discoverer technology...Hi,
You have got 2 options here. You can create a data item for each mime type and have a column for each mime type in the report. Each row would have a link in one of the columns. You will have to create a view or custom folder over your blob table with additional columns for each mime type, for example to create an extra column for Excel:
SELECT ...,
CASE WHEN mime_type = 'application/vnd.ms-excel' THEN blob_content END blob_exel
FROM blob_table
Then set the content_type in the properties of the folder to be XLS for blob_excel column. The user would then have to click on the column which had been populated with the link.
The other option is to write your own mod_plsql procedure to download the blob. It is quite simple, you need to call owa_util.mime_header to set the mime type and wpg_docload.download_file to download the blob. You then create a hyperlink to your mod_plsql procedure.
Hope that helps,
Rod West -
How to execute the content of varchar as query
Hi everyone!
I did a PL/SQL region in apex, in this region I did the query which is storaged in a variable; it was did it concatenate several times,
in the procedure I have several sentences.
I thought that the command 'execute immediate' would get a good result but it do not print the result.
declare
variable varchar2(1000);
begin
--sentences
--execute inmmediate( variable );
--return variable
end;
I only want to how to execute the content of varchar variable.
For example, suppose that the result of this procedure is
'SELECT SYSDATE FROM DUAL'
How and what do I must do for this query execute like a normal query that is in apex?
I expect your prompt reply.
Thank you for your help.
Best regardsErik,
Try dropping this into a PL/SQL region
DECLARE
v_result VARCHAR2(500);
BEGIN
SELECT SYSDATE
INTO v_result
FROM DUAL;
htp.prn(v_result);
END;
{code}
use the htp.prn command to write html you want to display. In this case we are just writing the date to the screen.
Good luck,
Tyson -
Control the query of Content By Search web part or a Catalog-Item Reuse web part from JavaScript
Is it possible/supported to intercept and change the query before it gets issued by a Content By Search or Catalog-Item Reuse webpart?
I am writing a multilingual site utilizing cross-site publishing mechanism, and the out-of-box (OOB) web parts would perfectly work if not for the following requirement that I've got: I need to serve location-specific content to the end user. I have several
versions of each content page for each geographical location, and I have tagged the pages accordingly with managed metadata keywords. I also can deduce the user's location from her browser's IP address and store it in a JavaScript variable. It is here
where I am getting stuck: I am trying to change on the fly the queries the web parts issue in order to attach the information about the user's geographical location, unsuccessfully so far.
I cannot rely on server-side code unless it is a cloud-hosted app code. I am about to give up and consider a custom solution alternative instead, which would be relying on Search REST API and custom client-side scripted widgets in place
of the OOB search web parts. This seems like an expensive alternative as the entire site could have been built using the OOB web parts, if not for the location requirement.
I would appreciate any suggestions.
Thanks in advance,
Ivan.hi
I would check several directions:
- in query transformation you may add keyword filter "Value of a field on the page". Documentation doesn't clearly says what "field" means here: is it only for site columns, or also may work for UI controls on the page. In second case it would solve your
problem (it would be possible to add hidden field on the page and set value via javascript). But chances that it works like this are not high;
- in the query settings of the Content by search web part there is setting "Loading behavior": Choose whether this query is issued on the server while the page is loading, which is better for your main content, or from the browser after the page appears.
I.e. if you will choose 2nd option there will be a chance to intercept the query on the client side in theory. All of this requires experimenting of course;
- by default Content by search web part sends query to /_vti_bin/client.svc/ProcessQuery with http post from client side (you may check it in fiddler). You may try to find the exact javascript function which performs the call and override it by adding additional
conditions to the query (fortunately it is not complicated in javascript).
Blog - http://sadomovalex.blogspot.com
Dynamic CAML queries via C# - http://camlex.codeplex.com
Maybe you are looking for
-
Macbook pro mid-2012 13" has very slow disk access
Until 3 days ago my macbook pro mid-2012 13" running OX 10.8.3 was running fine. Then, it showed very slow response anytime it had to access the hard disk. After doing the usual checks and disk first aid repairs to no avail, I booted from my external
-
Hi Team, I have iphone4 16GB with iOS 5.1.1. While using the phone, few times the phone is automatically going to shutdown and getting call disconnected. Some times, it happens more frequently in a day, sometimes not. and also, How can I update my
-
Buy on iTunes, my card has no CCV (security code)
I have a ebank account, they sent me the card... but the card has no CVV (security code) on the back, it's suppose to be 3 digits. So I made an PayPal account, but THEEEEEY won't send me a creditcard because I live outside the US. So I have an eAccou
-
hi, In my table i hav userid,user associationdate,user expirydate now i want to extend(update not select) all the user's expirydate to another one year and this should be done in SINGLE QUERY. how can i do this ? SQL> desc t_user_license Name Null? T
-
Running CF 7 on a Fedora Core Linux system that has the system level time zone updates applied. A shell command of 'date' returns the correct date and time. However, we have some CF services and webpages that rely on times and #timeFormat(now(), "sho