Function convertion from blob to clob
Plesae need help,to make function convert from blob to clob
i have function but not work when coulmn of blob is vey large
=========================================================================================
CREATE OR REPLACE PACKAGE BODY "SHB_PACKAGE"
AS
FUNCTION blob2clob (l_blob BLOB)
RETURN CLOB
IS
l_clob CLOB;
l_src_offset NUMBER;
l_dest_offset NUMBER;
l_blob_csid NUMBER := DBMS_LOB.default_csid;
v_lang_context NUMBER := DBMS_LOB.default_lang_ctx;
l_warning NUMBER;
l_amount NUMBER := dbms_lob.lobmaxsize;
BEGIN
IF l_blob is null
THEN
return null;
ELSE
DBMS_LOB.createtemporary (l_clob, TRUE);
l_src_offset := 1;
l_dest_offset := 1;
l_amount := NVL(DBMS_LOB.getlength (l_blob),0);
DBMS_LOB.converttoclob (l_clob,
l_blob,
l_amount,
l_src_offset,
l_dest_offset,
0,
v_lang_context,
l_warning
RETURN l_clob;
END IF;
END;
END SHB_package;
thanks,function is working fine
issue duo to i used under informatice and bug in informatica
Edited by: user8929623 on Jan 17, 2010 1:39 AM
Similar Messages
-
XML data from BLOB to CLOB - character set conversion
Hi All,
I'm trying to solve a problem with a character set conversion in PL/SQL in the following scenario:
1. source is an XML as a BLOB variable.
2. target is an XML as a CLOB variable.
3. the problem I have is the following:
- database character set is set to UTF-8
- XML character set could be anything (UTF-8, ISO 8859-1, ISO 8859-2, ASCII, ...)
- I need to write a procedure which converts the source BLOB content into the target CLOB taking into account the XML encoding and converts it into the DB default character set (UTF8).
I've been able to implement a simple conversion function. However, this function expects static XML encoding ISO-8859-1. The main part of the function looks as follows:
buffer := UTL_RAW.cast_to_varchar2(
UTL_RAW.convert(
DBMS_LOB.SUBSTR(source_blob_variable, 16000, pos)
, 'American_America.UTF8'
, 'American_America.we8iso8859p1')
Does anyone have an idea how to rewrite the code to handle "any" XML encoding in the source BLOB file? In other words, is there a function in Oracle which converts XML character set names into Oracle character set values (ISO-8859-1 to we8iso8859p1, UTF-8 to UTF8, ...)?
Thanks a lot for any help.
JuliusI want to pass a BLOB to some "createXML" procedure and get a proper XMLType in UTF8 character set, properly converted from whatever character set is the input in.As per documentation the generated XML has always the encoding set at the client side depending on NLS_LANG (default UTF-8), regardless of the input encoding, so I don't see a need to parse the PI of the XML:
C:\>echo %NLS_LANG%
%NLS_LANG%
C:\>sqlplus
SQL*Plus: Release 11.1.0.6.0 - Production on Wed Apr 30 08:54:12 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> var cur refcursor
SQL>
SQL> declare
2 b blob := utl_raw.cast_to_raw ('<a>myxml</a>');
3 begin
4 open :cur for select xmlroot (xmltype (utl_raw.cast_to_varchar2 (b))) xml from dual;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL>
SQL> print cur
XML
<?xml version="1.0" encoding="UTF-8"?><a>myxml</a>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
C:\>set NLS_LANG=GERMAN_GERMANY.WE8ISO8859P1
C:\>sqlplus
SQL*Plus: Release 11.1.0.6.0 - Production on Mi Apr 30 08:55:02 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
SQL> var cur refcursor
SQL>
SQL> declare
2 b blob := utl_raw.cast_to_raw ('<a>myxml</a>');
3 begin
4 open :cur for select xmlroot (xmltype (utl_raw.cast_to_varchar2 (b))) xml from dual;
5 end;
6 /
PL/SQL-Prozedur erfolgreich abgeschlossen.
SQL>
SQL> print cur
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<a>myxml</a> -
Hi,
Has anybody been successful in using the DBMS_LOB.ConvertToClob procedure. It's giving me "invalid lob locator specified" error.
here's my code
create or replace function convert_blob_to_clob(p_file in varchar2) return clob is
v_file_blob blob;
v_file_clob clob;
v_file_size integer := dbms_lob.lobmaxsize;
v_dest_offset integer := 1;
v_src_offset integer := 1;
v_blob_csid number := dbms_lob.default_csid;
v_lang_context number := dbms_lob.default_lang_ctx;
v_warning integer;
begin
select a.blob_content into v_file_blob
from txt_files a
where name = p_file;
dbms_lob.convertToClob(v_file_clob, v_file_blob,v_file_size,
v_dest_offset, v_src_offset, v_blob_csid,
v_lang_context, v_warning);
if v_warning = 0 then
return v_file_clob;
end if;
end;
Any help would be greatly appreciated
Thanks.I figured it out...
here 's the new code..
create or replace function convert_blob_to_clob(p_file in varchar2) return clob is
v_file_blob blob;
v_file_clob clob;
v_file_size integer := dbms_lob.lobmaxsize;
v_dest_offset integer := 1;
v_src_offset integer := 1;
v_blob_csid number := dbms_lob.default_csid;
v_lang_context number := dbms_lob.default_lang_ctx;
v_warning integer;
begin
select a.blob_content into v_file_blob
from txt_files a
where name = p_file;
-- the following line solved it
DBMS_LOB.CREATETEMPORARY(v_file_clob, TRUE);
dbms_lob.convertToClob(v_file_clob, v_file_blob,v_file_size,
v_dest_offset, v_src_offset, v_blob_csid,
v_lang_context, v_warning);
if v_warning = 0 then
return v_file_clob;
end if;
end; -
Procedure to convert from long to clob
please need to procedure migrate data from long to clob,with variables
V_SRC_TABLE (LONG) to V_TRAGT_TABLE (CLOB)
SOURCE AND TARGET TABLE HAVE TWO COLUMNS
SOURCE_TABLE
VARACHAR2
LONG
TARGET_TABLE
VARACHAR2
CLOBHi,
assuming you want to convert data always from source_table to target_table knowing the column names, let's say:
SQL> CREATE TABLE source_table(col1 VARCHAR2(10), col2 LONG);
Table created.
SQL> CREATE TABLE target_table(col1 VARCHAR2(10), col2 CLOB);
Table created.You can just copy the data using SQL:
INSERT INTO target_table SELECT col1, TO_LOB(col2) FROM source_table;Or, as a procedure:
CREATE OR REPLACE PROCEDURE migrate_to_clob IS
BEGIN
EXECUTE IMMEDIATE 'INSERT INTO target_table SELECT col1, TO_LOB(col2) FROM source_table';
END;Hope it helps. -
Converting from Blob to pdf problem
Dear all
I have a small problem i hope someone can help me with. I wrote a code that saves a pdf in a database as blob, but when trying to retrieve this blob back and show it as a pdf i had a problem.
When i tried to show the pdf it appeared as a long stream like the following
%PDF-1.6 %âãÏÓ 27 0 obj <> endobj xref 27 21 0000000016 0000 ...............etc.
so it has the same structure of my original pdf except that it's a long stream in only one line . The original pdf looks like the following
%PDF-1.6
%âãÏÓ
27 0 obj
<</Linearized 1/L 82015/O 38/E 6717/N 1/T 81428/H [ 716 197]>>
endobj
xref
27 21
............etc.
So if anyone can help to change that stream into a pdf again, i will really appreciate it. I attached the 2 files (the stream and the pdf).
Thanks in advanceYou should save the PDF data to a file and loading that into your HTML content.
This forum post may help:
http://forums.adobe.com/thread/430491 -
Can I convert existing column BLOB to CLOB?
Hi ,
I need conversion of existing column from BLOB to CLOB. Kindly sueggest workaround. Table structure is as
{ desc tab1;
Name Null? Type
Name Null? Type
RECID NOT NULL VARCHAR2(255)
XMLRECORD BLOB}
I need to convert it from blob to clob. Kindly provide workaround.
RegardsHi,
How can i use this function for my scenario
1. Table name is "test" and XMLRECORD column should be in CLOB without drop table. Kindly update this fuction as per my scenario and also provide all the steps
CREATE OR REPLACE FUNCTION blob_to_clob (blob_in IN BLOB)
RETURN CLOB
AS
v_clob CLOB;
v_varchar VARCHAR2(32767);
v_start PLS_INTEGER := 1;
v_buffer PLS_INTEGER := 32767;
BEGIN
DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(blob_in) / v_buffer)
LOOP
v_varchar := UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(blob_in, v_buffer, v_start));
DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_varchar), v_varchar);
v_start := v_start + v_buffer;
END LOOP;
RETURN v_clob;
END blob_to_clob;
] -
Stored Procedure or function to extract Blob
How can I extract Blob from Oracle to the way it was inserted in the db ? I tried using utl_raw but it gave me "Buffer too small"
ERROR at line 1:
ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual:
236143, maximum: 2000)I am trying this but it's not working for some reason:
create or replace function F(B BLOB)
return clob is
c clob;
n number;
begin
if (b is null) then
return null;
end if;
if (length(b)=0) then
return empty_clob();
end if;
dbms_lob.createtemporary(c,true);
n:=1;
while (n+32767<=length(b)) loop
dbms_lob.writeappend(c,32767,utl_raw.cast_to_varchar2(dbms_lob.substr(b,32767,n)));
n:=n+32767;
end loop;
dbms_lob.writeappend(c,length(b)-n+1,utl_raw.cast_to_varchar2(dbms_lob.substr(b,length(b)-n+1,n)));
return c;
end;
I get ORA-22921: length of input buffer is smaller than amount requested
ORA-06512: at "SYS.DBMS_LOB", line 833
ORA-06512: at "SYS.F", line 15 -
hi all,
i have a table have 2 clounms in my DB (10.2.0.4) one colunm is varchar2 and other one was blob. as per requested from developer team, i changed it from blob to clob. after this conversion, object size is increased from 11mb to 39mb. my point is is it expected behavior ?????? if yes ! can any one pl. explain it.
regards,CREATE TABLE TABLE_CLOB
RECID VARCHAR2(255 BYTE),
XMLRECORD SYS.XMLTYPE
TABLESPACE DATATABLESPACE
PCTUSED 0
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING
ENABLE ROW MOVEMENT;
CREATE UNIQUE INDEX TABLE_CLOB_PK ON TABLE_CLOB
(RECID)
LOGGING
TABLESPACE INDEXTABLESPACE
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
NOPARALLEL;
ALTER TABLE TABLE_CLOB ADD (
CONSTRAINT TABLE_CLOB_PK
PRIMARY KEY
(RECID)
USING INDEX
TABLESPACE INDEXTABLESPACE
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
)); -
I am using the below function to convert a CSV file with large data (say more than 100k records) . the below functions allows me to read not more than 350 records. Can any one help me with accepting the larger files ?
create or replace FUNCTION blob_to_clob (blob_in IN BLOB)
RETURN CLOB
AS
v_clob CLOB;
v_varchar VARCHAR2(32767);
v_start PLS_INTEGER := 1;
v_buffer PLS_INTEGER := 32767;
BEGIN
DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(blob_in) / v_buffer)
LOOP
v_varchar := UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(blob_in, v_buffer, v_start));
DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_varchar), v_varchar);
v_start := v_start + v_buffer;
END LOOP;
RETURN v_clob;
END blob_to_clob;Not sure why a BLOB is being used here. If you are processing just a CSV (text) file you shouldn't need a BLOB. You should be able to handle it directly as a CLOB. Could you detail more how you are using this function or what exactly your process is doing i.e. how is the data read in from CSV, where does it go, etc.?
-
Using blob or clob from db as document
I'm changing a working process to fetch an XDP document from a database rather than fetch from resources:// on the Adobe server. The DB2 database field containing the XDP is a clob data type. We were using blob. The services operations are:
- Foundation/JdbcService/Query Single Row this fetches the XDP
- Foundation/SetValue/Execute this converts whatever was fetched into a document variable
- Forms/FormsService/renderPDFForm this merges the document with XML and produces PDF output
I'm unable to write the database field into a variable due to lack of choices. For instance there is no BLOB or CLOB variable type in the list of available types. When using STRING I get the following error:
Caused by: java.io.NotSerializableException: com.ibm.db2.jcc.b.ub
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
at com.adobe.idp.dsc.util.CoercionUtil.toString(CoercionUtil.java:498)
When using XML I get the following error:
Caused by: com.adobe.workflow.WorkflowRuntimeException: Invalid location: /process_data/@clob_XDP_string cannot be stored for action instance: -1
at com.adobe.workflow.pat.service.PATExecutionContextImpl.setProcessDataValue(PATExecutionCo ntextImpl.java:701)
When using OBJECT I get the following error:
Caused by: com.adobe.workflow.WorkflowRuntimeException: Invalid location: /process_data/@clob_XDP_string cannot be stored for action instance: -1
at com.adobe.workflow.pat.service.PATExecutionContextImpl.setProcessDataValue(PATExecutionCo ntextImpl.java:701)Steve,
Going against DB2 doesn't work for me with a document variable type. It gives a coercion error.
I did solve my problem though from the following URL: http://groups.google.com/group/livecycle/browse_thread/thread/6c4b9156b52b71a7
JYates:
You can do this, but you have to use the Execute Script service -- at this time there isn't a deployable component for it.
Use this sort of script in the Execute Script service to read the PDF blob from the database and populate a Document variable.
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import javax.sql.DataSource;
import javax.naming.InitialContext;
int processId = patExecContext.getProcessDataIntValue("/process_data/@id");
InitialContext context = new InitialContext();
Connection connection = ((DataSource)context.lookup("java:/IDP_DS")).getConnection();
String queryQuery = "select bigdocument, bigstring from tb_pt_workwithxlobs where process_instance_id = ?";
PreparedStatement queryStatement = connection.prepareStatement(queryQuery);
try {
queryStatement.setInt(1, processId);
ResultSet results = queryStatement.executeQuery();
results.next();
java.sql.Blob documentBlob = results.getBlob(1);
com.adobe.idp.Document document = new com.adobe.idp.Document(documentBlob.getBinaryStream());
patExecContext.setProcessDataValue("/process_data/@NewBigDocument",document);
java.sql.Clob stringClob = results.getClob(2);
patExecContext.setProcessDataValue("/process_data/@NewBigString",stringClob.getSubString( 1L,(int)stringClob.length()));
catch(Exception ex) {
ex.printStackTrace();
queryStatement.close();
connection.close(); -
Limitation of converting from Long Raw to Blob
Hi All,
DB:11g
Oracle Apps:R12
Is there a limitation of converting from Long Raw to Blob?
Please share your experience on this subject in case anyone has faced it before.
Thanks for your time!
Regards,http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:13213885403654
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:510622111991 -
How to convert from varchar to blob ?
How to convert from varchar to blob ?
thanksHere is a small PL/SQL block that we have used to convert varchar2 to blob.
declare
cursor get_blob is
select blob_statement
from report
where report_id = 205
FOR UPDATE OF blob_statement;
v_loc blob;
v_raw_buffer raw(32767);
v_amount binary_integer := 32767;
v_offset binary_integer := 1;
v_buffer VARCHAR2(32767);
begin
open get_blob;
fetch get_blob into v_loc;
close get_blob;
v_buffer := 'Sample text';
v_raw_buffer := utl_raw.cast_to_raw(v_buffer);
v_amount := utl_raw.length(v_raw_buffer);
dbms_lob.write(v_loc, v_amount, v_offset, v_raw_buffer);
commit;
end; -
Detecting character encoding from BLOB stream... (PLSQL)
I'am looking for a procedure/function which can return me the character encoding of a "text/xml/csv/slk" file stored in BLOB..
For example...
I have 4 files in different encodings (UTF8, Utf8BOM, ISO8859_2, Windows1252)...
With java I'can simply detect the character encoding with JuniversalCharDet (http://code.google.com/p/juniversalchardet/)...
thank youSolved...
On my local PC I have installed Java 1.5.0_00 (because on DB is 1.5.0_10)...
With Jdeveloper I have recompiled source code from:
http://juniversalchardet.googlecode.com/svn/trunk/src/org/mozilla/universalchardet
http://code.google.com/p/juniversalchardet/
After that I have made a JAR file and uploaded it with loadjava to my database...
C:\>loadjava -grant r_inis_prod -force -schema insurance2 -verbose -thin -user username/password@ip:port:sid chardet.jarAfter that I have done a java procedure and PLSQL wrapper example below:
public static String verifyEncoding(BLOB p_blob) {
if (p_blob == null) return "-1";
try
InputStream is = new BufferedInputStream(p_blob.getBinaryStream());
UniversalDetector detector = new UniversalDetector(null);
byte[] buf = new byte[p_blob.getChunkSize()];
int nread;
while ((nread = is.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
detector.dataEnd();
is.close();
return detector.getDetectedCharset();
catch(Exception ex) {
return "-2";
}as you can see I used -2 for exception and -1 if input blob is null.
then i have made a PLSQL procedure:
function f_preveri_encoding(p_blob in blob) return varchar2 is
language Java name 'Zip.Zip.verifyEncoding(oracle.sql.BLOB) return java.lang.String';After that I have uploaded 2 different txt files in my blob field.. (first one is encoded with UTF-8, second one with WINDOWS-1252)..
example how to call:
declare
l_blob blob;
l_encoding varchar2(100);
begin
select vsebina into l_blob from dok_vsebina_dokumenta_blob where id = 401587359 ;
l_encoding := zip_util.f_preveri_encoding(l_blob);
if l_encoding = 'UTF-8' then
dbms_output.put_line('file is encoded with UTF-8');
elsif l_encoding = 'WINDOWS-1252' then
dbms_output.put_line('file is encoded with WINDOWS-1252');
else
dbms_output.put_line('other enc...');
end if;
end;Now I can get encoding from blob and convert it to database encoding and store datas in CLOB field..
Here you have a chardet.jar file if you need this functionality..
https://docs.google.com/open?id=0B6Z9wNTXyUEeVEk3VGh2cDRYTzg
Edited by: peterv6i.blogspot.com on Nov 29, 2012 1:34 PM
Edited by: peterv6i.blogspot.com on Nov 29, 2012 1:34 PM
Edited by: peterv6i.blogspot.com on Nov 29, 2012 1:38 PM -
Hi All,
Any help with be much appreciated.
I wrote the following but keep getting the following error: ORA-06502: PL/SQL: numeric or value error. I know the flex_ws_api.blob2clobbase64 function is working as I have tested it outside of the application but when I try to push it to a page item I get the error, the function is converting a document form a blob to a clob.
declare
l_blob BLOB;
l_return CLOB;
BEGIN
select blob_content into l_blob
from wwv_flow_files
where name = :P169_FILENAME;
l_return := flex_ws_api.blob2clobbase64(l_blob);
:P169_CLOB_VALUE := l_return;
END;user10256482 wrote:
:P169_CLOB_VALUE defined as just a textarea item and the error I receive is in the Application (APEX) so I dont get a line number.I'm thinking :p169_clob_value was defined with insufficient length and the clob is too long to fit into it -
Blob to clob conversion when inserting as select?
I have a table with one row that has BLOB column. I would like to copy that row to a different table, with CLOB column data type. I’ve found this discussion (BLOB to CLOB? where some examples of stored procedures to convert blob to clob are used but I am unsure what should I use as input parameter to the blob_to_clob procedures listed in that discussion? Please advice.
Thank you very much for your time.
DanielThe function by Richard Wiener {message:id=9646697} in the thread simply uses the procedure dbms_lob.converttoclob with a set of parameters defined in the function.
At my work we have created a similar function:
CREATE OR REPLACE function blob2clob (p_blob in blob)
return clob
is
v_clob clob;
amount INTEGER;
dest_offset INTEGER;
src_offset INTEGER;
blob_csid NUMBER;
lang_context INTEGER;
warning INTEGER;
begin
dbms_lob.createtemporary (
v_clob,
false,
dbms_lob.session
amount := dbms_lob.lobmaxsize;
dest_offset := 1;
src_offset := 1;
blob_csid := nls_charset_id('AL32UTF8');
lang_context := 0;
dbms_lob.converttoclob(
v_clob,
p_blob,
amount,
dest_offset,
src_offset,
blob_csid,
lang_context,
warning
return v_clob;
end blob2clob;
/Difference here is that Richard uses default charset - we have need for AL32UTF8 charset. You should use whatever is relevant for your case.
The use of either Richards function or the above is simple for your insert as select:
insert into tab_c (clob_col)
select blob_to_clob(blob_col) from tab_b
Maybe you are looking for
-
Team, Unable to start FE service on one of the FE server, 2 Enterprise lync 2013 pool one FE in each pool, only following error in event vrw, Log Name: Lync Server Source: LS Server Date: 12/30/2013 12:10:55 PM Event ID: 122
-
I have files on time machine backup that I want to delete; (the original files I've deleted in the internal drive. When I try to delete, I get a message saying the I can't delete backup files??? GH
-
Will Adobe ever add support for JPEG-XR?
There's been quite a bit of work done on the Flash Player to display and export JPEG-XR files. During the Flash CS6 prerelease, the Flash team talked about additional JPEG-XR support for things like spritesheet creation. I know there's an ancient Pho
-
Custom event never reaching Listening function
Hi all, I have been having a problem usign a custom event... I attached it to the the main class using "addEventListener" and fire it off with "dispatchEvent" in another class. I checked that it was attached to the main class using "hasEventListener"
-
Can't record sound on HP Pavilion Elite HPE
I have Windows 7 installed and am trying to get Dragon Premium to work on my computer. Unfortunately, I've tried two different mikes and neither can record on my system. I've gone through all the standard troubleshooting for sound recording. The