LOB : how convert CLOB into BLOB
This code doesn't work : ORA-06502: PL/SQL: numeric or value error: hex to raw conversion error.
declare
vCLOB CLOB := empty_clob();
vBLOB BLOB := empty_blob();
begin
dbms_lob.createTemporary(vCLOB,TRUE);
dbms_lob.open(vCLOB, DBMS_LOB.LOB_READWRITE);
-- Put data into CLOB
l_length := dbms_lob.getlength(vCLOB);
dbms_lob.read(vCLOB,l_length,1,buffer);
dbms_lob.createTemporary(vBLOB,TRUE);
dbms_lob.open(vBLOB, DBMS_LOB.LOB_READWRITE);
dbms_lob.write(vBLOB,l_length,1,buffer);
dbms_lob.close(vBLOB);
dbms_lob.freeTemporary(vBLOB);
dbms_lob.close(vCLOB);
dbms_lob.freeTemporary(vCLOB);
Thanks.
You can use my procedure
create or replace procedure CLOB2BLOB (p_clob in out nocopy clob, p_blob in out nocopy blob) is
-- transforming CLOB â BLOB
l_off number default 1;
l_amt number default 4096;
l_offWrite number default 1;
l_amtWrite number;
l_str varchar2(4096 char);
begin
begin
loop
dbms_lob.read ( p_clob, l_amt, l_off, l_str );
l_amtWrite := utl_raw.length ( utl_raw.cast_to_raw( l_str) );
dbms_lob.write( p_blob, l_amtWrite, l_offWrite,
utl_raw.cast_to_raw( l_str ) );
l_offWrite := l_offWrite + l_amtWrite;
l_off := l_off + l_amt;
l_amt := 4096;
end loop;
exception
when no_data_found then
NULL;
end;
end;
Best regards, Victor
Similar Messages
-
I am trying to convert clob into blob through following code.
CREATE OR REPLACE FUNCTION clob_to_blob (clob_in IN CLOB)
RETURN BLOB
AS
v_blob BLOB;
v_varchar RAW(32767);
v_start BINARY_INTEGER := 1;
v_buffer BINARY_INTEGER := 32767;
BEGIN
FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(clob_in) / v_buffer)
LOOP
v_varchar := UTL_RAW.CAST_TO_RAW(DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start)) ;
DBMS_OUTPUT.PUT_LINE('DATA :' ||DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start));
DBMS_OUTPUT.PUT_LINE(' V_VARCHAR :'|| v_VARCHAR);
DBMS_OUTPUT.PUT_LINE(' V_VARCHAR LENGTH :'|| LENGTH(v_VARCHAR));
DBMS_LOB.WRITEAPPEND(v_blob, LENGTH(v_VARCHAR), v_varchar);
DBMS_OUTPUT.PUT_LINE('after append');
v_start := v_start + v_buffer;
END LOOP;
RETURN v_blob;
END clob_to_blob;
calling code:
declare
var clob;
begin
var:='3433534534de';
testblob(var);
end;
It gives me following error:
declare
ERROR at line 1:
ORA-21560: argument 2 is null, invalid, or out of range
i don't know whats the prob?
thanxdbms_lob.writeappend expects a real lob locator, which you can only get by selecting from a lob column.
create table blobtab (b blob);
insert into blobtab values (empty_blob());
CREATE OR REPLACE FUNCTION clob_to_blob (clob_in IN CLOB)
RETURN BLOB
AS
v_blob blob;
v_varchar RAW(32767);
v_start BINARY_INTEGER := 1;
v_buffer BINARY_INTEGER := 32767;
BEGIN
select b into v_blob from blobtab;
FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(clob_in) / v_buffer)
LOOP
v_varchar := UTL_RAW.CAST_TO_RAW(DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start)) ;
DBMS_OUTPUT.PUT_LINE(' DATA :' || DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start));
DBMS_OUTPUT.PUT_LINE(' V_VARCHAR :' || v_VARCHAR);
DBMS_OUTPUT.PUT_LINE(' V_VARCHAR LENGTH :' || utl_raw.LENGTH(v_VARCHAR));
DBMS_LOB.WRITEAPPEND(v_blob, utl_raw.LENGTH(v_VARCHAR), v_varchar);
DBMS_OUTPUT.PUT_LINE('after append');
v_start := v_start + v_buffer;
END LOOP;
RETURN v_blob;
END clob_to_blob;
declare
blobvar blob;
begin
blobvar := clob_to_blob(dbms_xmlgen.getXML('select 1 from dual'));
end;
/ -
How to convert CLOB to BLOB with SQL Developer migration wizard?
Hi,
According to our requirement, we need to only migrate data from SQL Server 2008 to Oracle 11. I use the SQL Developer 3.0.04 migration wizard to do it.
I do migration from SQL Server (database name: SCDS41P2) to Oracle (User name: HCDS41P2).
My migration steps are as below: (I need to modify the target schema, so I add the steps 2) and step 3) )
1) Do migration by SQL Developer migration wizard;
2) Remove the Converted Database Objects node from migration project;
3) Re-do convert by SQL Developer migration wizard (contains changing the target schema);
When do step 1), the DBO_SCDS41P2 user is created automatically. CLOBTOBLOB_SQLDEVELOPER procedure is also created in this user.
I continued to run step 2) and step 3) with online mode. And find the table data which contains BLOB column can be moved into the target table. But from the Logging Page, I can't see the other detailed error info, so that I can't check which tables don't move data successfully.
Could you please tell me where the detail log file (e.g. contains every table's migration status) is if I use the online mode?
Additional, If I use offline mode to do step 3), I found the CLOB data can't be converted into BLOB automatically. Because in the load script (that is oracle_ctl.bat), only copy the source data to the CLOB column. After copy, it don't deal with the converting from CLOB to BLOB.
So could you please tell me how to convert CLOB to BLOB with offline mode?
Thanks so much.Hi,
For your first question about logging - after the migration there will be an entry in the right hand panel for the migration project. If you open this there are various fields that give information about the status of each part of the migration. Does this give you the information you need ?
For the second problem about offline moving blob data have a look at the SQL*Developer documentation -
Oracle® SQL Developer User’s Guide Release 3.0
in the section -
2.2.8.1.4 Populating the Destination Database Using the Data Files
which describes the problem and how to get round it.
Regards,
Mike
Edited by: mkirtley on Aug 12, 2011 10:49 AM -
Converting CLOB to BLOB at once
Hello all!
I have to convert CLOB to BLOB in my application. My CLOB contains XML document built with dbms_xmldom, an I need to put it into column of type BLOB. Knowing several ways to do it, I'm searching for the best one. So I considered the folowing:
- Size of XML data can be more then 4000 bytes.
- I can convert it "piecewise", copying through varchar2 and raw buffers by chunks. But this is not efficient for me.
- I can write CLOB to file, then read it into BLOB. But it is not efficient too.
- I can not change column type to CLOB since it may contain other BLOB data, not XML.
Actually, I need a way to "cast" CLOB data as binary data when inserting into table. I believe Oracle must have it, but where?
I'll be very grateful for help from anyone.
P.S. Using Oracle 9.2You could use UTL_RAW.CAST_TO_RAWhttp://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_raw2.htm#998330
The XML data can be 32k (the varchar2 limit in PLSQL is 32k, not 4000 bytes)
If your documents exceeds 32k you need process chunks -
hi
tell me some thong how we can convert clob to blobYou can use my procedure
create or replace procedure CLOB2BLOB (p_clob in out nocopy clob, p_blob in out nocopy blob) is
-- transforming CLOB â BLOB
l_off number default 1;
l_amt number default 4096;
l_offWrite number default 1;
l_amtWrite number;
l_str varchar2(4096 char);
begin
begin
loop
dbms_lob.read ( p_clob, l_amt, l_off, l_str );
l_amtWrite := utl_raw.length ( utl_raw.cast_to_raw( l_str) );
dbms_lob.write( p_blob, l_amtWrite, l_offWrite,
utl_raw.cast_to_raw( l_str ) );
l_offWrite := l_offWrite + l_amtWrite;
l_off := l_off + l_amt;
l_amt := 4096;
end loop;
exception
when no_data_found then
NULL;
end;
end;
Best regards, Victor -
Anyone know an easy way to convert clob data to blob data?
We upgraded a client to 8.1.7.2 and now we can no longer store MS-Word templates to the RDBMS.
I deduce this is because MS-Word templates are binary files.
Earlier versions of 8.1.7 and 8.1.6 allowed us to do this. However, this is no longer the case.
Some of my clob rows are over 6 meg.
I have written some PL/SQL code to basically retrieve the clob data in cursor, loops through the clob in 32767 blocks,
performing dbms_lob.substr, converts that data to hex(major pain), & then write the blocks using dbmbs_lob.write.
I keep getting the proverbial "ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275".
Does anyone see flaws in my approach and might have an easier solution?
Thanks!Here's my code:
REATE OR REPLACE
PROCEDURE p_load_clob_to_blob IS
* Name: p_load_clob_to_blob
* Parameters: None
* Purpose: This procedure loads the narr_blob column in the narr table_text with clob data from the
* narr column.
* Notes: This procedure assumes that narr table has been altered with narr_blob column added.
* See the SQL below:
* alter table narr_text add (narr_blob blob);
* Once this procedure executes, the table must altered to drop the narr_text clob column,
* recreate the narr_text as blob, & then repopulate narr_text. See the SQL below:
* alter table narr_text drop column narr;
* alter table narr_text add (narr blob);
* update narr_text set narr = narr_blob;
* commit;
* Called By: Sys Admin
* CHANGE LOG
* Changed By Date Change Description
* EAO 01/16/02 Created.
rec_read INTEGER;
rec_update INTEGER;
write_cnt INTEGER;
write_amount BINARY_INTEGER;
write_offset INTEGER;
write_loop INTEGER;
total_length NUMBER;
total_written NUMBER;
buffer VARCHAR2(32767);
bbuffer RAW(32767);
temp_narr_id NUMBER;
max_loop INTEGER;
cx CLOB;
bx BLOB;
bx2 BLOB;
cur_evt varchar2(50); -- current event
v_err_descr varchar2(256);
i INTEGER;
hex varchar(32767);
CURSOR c_load_narr_clob IS
SELECT narr, narr_id
FROM narr_text
where narr_id = 6366;
BEGIN
insert_event_log('', 'p_load_clob_to_blob', '', '', '', 'p_load_clob_to_blob started', '');
rec_read := 0;
rec_update := 0;
---Fill file
insert_event_log('', 'p_load_clob_to_blob ','c_load_narr_clob ', '', 'S', 'c_narr_clob started', '');
FOR csr IN c_load_narr_clob LOOP
cur_evt := 'Select narr from narr table: ';
rec_read := rec_read + 1;
write_loop := 1;
write_cnt := 0;
write_offset := 1;
total_written := 0;
cx := csr.narr;
bx := empty_blob();
total_length := DBMS_LOB.GETLENGTH(cx);
max_loop := (total_length / 32767) + 1;
if (total_length <= 32767) THEN
write_amount := total_length;
ELSE
write_amount := 32767;
END IF;
dbms_output.put_line('Length=' || to_char(total_length) || ' Max loop=' || to_char(max_loop) || ' Write Amount=' || to_char(write_amount));
temp_narr_id := csr.narr_id;
while write_cnt < max_loop
loop
--FOR write_loop in 1..max_loop LOOP
delete temp_blob;
delete temp_raw;
commit;
cur_evt := 'Dbms_lob.substr: ';
dbms_output.put_line(cur_evt);
buffer := DBMS_LOB.SUBSTR(cx, write_amount, write_offset);
dbms_output.put_line('Write Amount='|| to_char(write_amount) || ' Write Offset=' || to_char(write_offset) );
cur_evt := 'Hex to Raw Assigment: ';
dbms_output.put_line(cur_evt);
bbuffer := null;
for i in 1..write_amount loop
hex := numtohex(ascii(substrb(buffer,i,1)));
bbuffer := bbuffer || hextoraw(hex);
end loop;
cur_evt := 'Insert temp_raw: ';
dbms_output.put_line(cur_evt);
insert into temp_raw(rx)
values (bbuffer);
commit;
cur_evt := 'Insert temp_blob: ';
dbms_output.put_line(cur_evt);
execute immediate 'insert into temp_blob(bx)
select TO_LOB(rx) from temp_raw';
commit;
cur_evt := 'Select bx2: ';
dbms_output.put_line(cur_evt);
bx2 := empty_blob();
select bx into bx2 from temp_blob;
cur_evt := 'Dbms_lob.append: ';
dbms_output.put_line(cur_evt);
dbms_lob.append(bx, bx2);
dbms_output.put_line('Write Amount='|| to_char(write_amount) || ' Write Offset=' || to_char(write_offset) );
write_offset := write_offset + write_amount;
total_written := total_written + write_amount;
write_cnt := write_cnt + 1;
if (write_cnt = max_loop) then
write_amount := total_length - total_written;
end if;
END LOOP;
dbms_output.put_line('Total_written = ' || to_char(total_written) );
cur_evt := 'Upd narr_blob in narr table: ';
update narr_text
set narr_blob = bx
where narr_id = temp_narr_id;
rec_update := rec_update + 1;
commit;
END LOOP;
insert_event_log('', 'p_load_clob_to_blob ','c_load_narr_clob ', '', 'C', 'c_narr_clob completed', '');
dbms_output.put_line('Records read=' || to_char(rec_read) || ' Records updated=' || to_char(rec_update) );
insert_event_log('', 'p_load_clob_to_blob', '', '', '', 'p_load_clob_to_blob ended', '');
EXCEPTION
WHEN OTHERS THEN
Rollback;
v_err_descr := 'FATAL ERROR OCCURRED -'||cur_evt||sqlerrm;
dbms_output.put_line (v_err_descr);
END;
FUNCTION numtohex(v_hex number) return varchar2
is
hex varchar2(4);
num1 number;
num2 number;
begin
num1 := trunc(v_hex/16);
num2 := v_hex-(num1*16);
if ( num1 >= 0 and num1 <= 9 ) then
hex := hex||to_char(num1);
end if;
if num1 = 10 then hex := hex||'A'; end if;
if num1 = 11 then hex := hex||'B'; end if;
if num1 = 12 then hex := hex||'C'; end if;
if num1 = 13 then hex := hex||'D'; end if;
if num1 = 14 then hex := hex||'E'; end if;
if num1 = 15 then hex := hex||'F'; end if;
if ( num2 >= 0 and num2 <= 9 ) then
hex := hex||to_char(num2);
end if;
if num2 = 10 then hex := hex||'A'; end if;
if num2 = 11 then hex := hex||'B'; end if;
if num2 = 12 then hex := hex||'C'; end if;
if num2 = 13 then hex := hex||'D'; end if;
if num2 = 14 then hex := hex||'E'; end if;
if num2 = 15 then hex := hex||'F'; end if;
return hex;
end; -
Invalid data after converting clob to blob
GOAL: insert adresse or someth. into an msword file out of database
Hi,
I'm working with a 9i database and I'm trying to insert data in a clob. First I convert the blob, which is a stored xml- file in my databse, to a clob. after that i'm replacing the data I want to insert and then reconverting to blob. It goes very well, but when the data I insert contains a 'ö' or 'ä' or 'ß' the blob file i get is invalid and can't be read by msword! I opened the file with notepad and instead of 'ö' etc there is a very strange sign like a square. here is my plsql- code:
loop
test:=substr(v_clob,posi,len);
posi:=posi+32767;
if length(v_clob)-posi<32767 then
len:=length(v_clob)-posi+1;
end if;
--vartest:=utl_raw.cast_to_raw(v_clob);
DBMS_LOB.WRITE(r_blob, length(test),posi-32767, utl_raw.cast_to_raw(test));
exit when posi>length(v_clob);
end loop;
DBMS_LOB.freetemporary(v_clob);
return r_blob;
because of 9i doesn't contain the procedure dbms_lob.converttoblob i user utl_raw.cast_to_raw and split my clob in several parts with a size of 32767 characters
i also tried with utl_raw.convert with several character sets, but don't know which one to take...
nls_lang of database server is set to GERMAN_GERMANY.WE8MSWIN1252
can anyone help me please!
Message was edited by:
user472439dbms_lob.writeappend expects a real lob locator, which you can only get by selecting from a lob column.
create table blobtab (b blob);
insert into blobtab values (empty_blob());
CREATE OR REPLACE FUNCTION clob_to_blob (clob_in IN CLOB)
RETURN BLOB
AS
v_blob blob;
v_varchar RAW(32767);
v_start BINARY_INTEGER := 1;
v_buffer BINARY_INTEGER := 32767;
BEGIN
select b into v_blob from blobtab;
FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(clob_in) / v_buffer)
LOOP
v_varchar := UTL_RAW.CAST_TO_RAW(DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start)) ;
DBMS_OUTPUT.PUT_LINE(' DATA :' || DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start));
DBMS_OUTPUT.PUT_LINE(' V_VARCHAR :' || v_VARCHAR);
DBMS_OUTPUT.PUT_LINE(' V_VARCHAR LENGTH :' || utl_raw.LENGTH(v_VARCHAR));
DBMS_LOB.WRITEAPPEND(v_blob, utl_raw.LENGTH(v_VARCHAR), v_varchar);
DBMS_OUTPUT.PUT_LINE('after append');
v_start := v_start + v_buffer;
END LOOP;
RETURN v_blob;
END clob_to_blob;
declare
blobvar blob;
begin
blobvar := clob_to_blob(dbms_xmlgen.getXML('select 1 from dual'));
end;
/ -
Converting varchar2 to BLOB or converting CLOB to BLOB
Hi i am using a table where i have to convert a field currently existing as a varchar2 or CLOB to a BLOB field.
while doing this i also have to preserve the data currently existing in the table.
Please help.
ThanksCLOB to a BLOB CREATE OR REPLACE FUNCTION clob_to_blob (clob_in IN CLOB) RETURN BLOB AS
v_blob BLOB;
v_varchar RAW(32001);
v_varchar1 RAW(32001);
v_start INTEGER := 1;
v_buffer INTEGER := 32001;
BEGIN
DBMS_LOB.CREATETEMPORARY(v_blob, TRUE);
FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(clob_in) / v_buffer) LOOP
DBMS_LOB.READ(clob_in,v_buffer,v_start,v_varchar);
DBMS_LOB.WRITEAPPEND(v_blob, utl_raw.length(v_varchar), v_varchar);
v_start := v_start + v_buffer;
END LOOP;
RETURN v_blob;
END clob_to_blob;
/ -
How to convert clobs to blobs?
What is the easiest way to go if I want to copy the content of a CLOB to a BLOB(Other than reading the contents of the CLOB out into a buffer and then apply UTL_RAW.CAST_TO_RAW)? How about from blobs to clobs?
nullHi,
create table myblob(x blob);
create table myblob1(x clob);
create or replace procedure blob_to_clob as
b_lob blob;
buffer VARCHAR2(32000);
g_length number;
begin
select x into b_lob from myblob;
g_length := dbms_lob.getlength(b_lob);
dbms_lob.read(b_lob,g_length,1,buffer);
insert into myblob1 values(buffer);
commit;
end;
null -
Optimize a data parser that converts CLOB into table
I am importing complex array data from Cold Fusion into ORACLE using a stored procedure. What I've done is convert the data into a CLOB, pass it into ORACLE, then parse it into a temporary table using a pipelined function. Unfortunately the array is large (16k rows) and it's taking a while to run.
What I'm looking is a better optimization for the data conversion. I've tried XML and the dbms_xmlstore but it was too slow. I am on 10g and don't have access to the log files or even the ability to trace anything. All I can do is look for better ways to do things and then try them.
Any suggestions or help to improve things would be welcome.
Warren Koch
The function converts the array of object into a custom delimited CLOB ( ; betwen values, | between rows) that looks like this:
prop1;prop2;prop3|prop1;prop2;prop3|prop1;prop2;prop3|prop1;prop2;prop3|
Here is the code I created.
CREATE OR REPLACE TYPE THE_IMAGE_TYPE AS OBJECT
IMAGE_NAME VARCHAR2(100),
IMAGE_SIZE INTEGER,
IMAGE_LOC INTEGER
CREATE OR REPLACE TYPE THE_IMAGE_TABLE AS TABLE OF THE_IMAGE_TYPE
CREATE GLOBAL TEMPORARY TABLE IMAGE_IMPORT
image_name VARCHAR2(25 BYTE),
loc NUMBER(11),
image_size NUMBER(11)
ON COMMIT PRESERVE ROWS
NOCACHE;
FUNCTION convert_image_data(
in_image_clob IN CLOB
RETURN the_image_table PIPELINED
AS
image_clob CLOB := in_image_clob;
image_delim_index PLS_INTEGER;
image_index PLS_INTEGER := 1;
row_string VARCHAR2(1000);
out_rec THE_image_type;
BEGIN
out_rec := the_image_type(NULL, NULL, NULL);
IF SUBSTR(in_image_clob, -1, 1) != '|'
THEN
image_clob := image_clob || '|';
END IF;
image_delim_index := INSTR(image_clob, '|', image_index);
WHILE image_delim_index > 0
LOOP
row_string := SUBSTR(image_clob, image_index, image_delim_index - image_index);
row_string := REPLACE(row_string || '::::', ':', ' :');
out_rec.image_name := SUBSTR(TRIM(REGEXP_SUBSTR(row_string, '[^:]+', 1, 1)), 1, 25);
out_rec.image_loc := make_number(REGEXP_SUBSTR(row_string, '[^:]+', 1, 2));
out_rec.image_size := make_number(REGEXP_SUBSTR(row_string, '[^:]+', 1, 3));
PIPE ROW(out_rec);
image_index := image_delim_index + 1;
image_delim_index := INSTR(image_clob, '|', image_index);
END LOOP;
RETURN;
EXCEPTION
WHEN OTHERS
THEN
RAISE;
END;
Used in my code like this:
EXECUTE IMMEDIATE 'TRUNCATE TABLE image_import';
FOR x IN (SELECT * FROM TABLE(convert_image_data(in_imagelist))
WHERE image_name IS NOT NULL)
LOOP
INSERT INTO image_import (image_name, loc, image_size)
VALUES (x.image_name, x.image_loc, x.image_size);
END LOOP;Is there any chance you can just use 1 SQL statement here? I gave it a shot based on the string you posted, not by trying to reverse engineer your code so it's possible i got it entirely wrong :)
select
regexp_substr(image_row, '[^;]+', 1, 1) as image_name,
regexp_substr(image_row, '[^;]+', 1, 2) as image_size,
regexp_substr(image_row, '[^;]+', 1, 3) as image_loc
from
select
regexp_substr(the_data, '[^|]+', 1, level) as image_row
from
select
'prop1;prop2;prop3|prop4;prop5;prop6|propa;propb;propc|propd;prope;propf|' as the_data
from dual
connect by level <= length (regexp_replace(the_data, '[^|]+')) + 1
17 where image_row is not null;
IMAGE_NAME IMAGE_SIZE IMAGE_LOC
prop1 prop2 prop3
prop4 prop5 prop6
propa propb propc
propd prope propf
4 rows selected.
Elapsed: 00:00:00.00 -
Multiplatform: how convert int into byte[]???
Hi all,
I need to convert an int value into an array of bytes. An int is represented by 4 bytes, but the problem is that depending on the platform, the most significant byte is the first or the last, so if you convert it directly, like:
int i = 5;
byte b[] = new byte[4];
b[0] = (byte)( (i & 0xff000000) >>> 24);
b[1] = (byte)( (i & 0x00ff0000) >>> 16);
b[2] = (byte)( (i & 0x0000ff00) >>> 8);
b[3] = (byte)( (i & 0x000000ff) );
you cannot export it to another platfroms.
Thank you in advance.Come on, nobody knows how to detect the byte order in a given platform?
I've been all the day dealing with this, which means all day without producing.
Please, it�s very urgent.
Thank you again. -
How convert integer into string
Hi,
I need to convert answer3 from double into String
answer3 = Double.parseDouble(dij3)/(1 + Math.pow(( Double.parseDouble(tesside_luas_i) / Double.parseDouble(tesside_luas_j) ),0.5847));Now the integer value is string but why i cannot get valur from my servlet to my web page
package net.mybizaid.isodms.servlet;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import net.mybizaid.isodms.*;
public class SPLDataInputServlet extends HttpServlet {
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
System.out.println( "******************** Calculation Servlet ******************" );
String dij ;
String population_i ;
String population_j ;
String project_name = "";
String project_status = "";
double answer;
String handler = "";
String url = "";
double answer3;
String dij3 ="";
String tesside_luas_i ="";
String tesside_luas_j ="";
double answer2;
String dij2 ="";
String luas_i ="";
String luas_j ="";
String counter = "";
String i = "";
handler = request.getParameter( "handler" );
dij = request.getParameter("dij");
population_i = request.getParameter("population_i");
population_j = request.getParameter( "population_j");
project_name = request.getParameter( "project_name");
project_status = request.getParameter( "project_status");
dij2 = request.getParameter("dij2");
luas_i = request.getParameter("luas_i");
luas_j = request.getParameter( "luas_j");
dij3 = request.getParameter("dij3");
tesside_luas_i = request.getParameter("tesside_luas_i");
tesside_luas_j = request.getParameter( "tesside_luas_j");
HttpSession session = null;
session = request.getSession(true);
int cnt = counter != null && !counter.equals("") ? Integer.parseInt(counter) : 0;
int ii = i != null && !i.equals("") ? Integer.parseInt(i) : 0;
//Tesside
if (handler != null && !handler.equals( "" ) && handler.equals( "cal3" ))
try
System.out.println("The DIJ3 value is :"+dij3);
System.out.println("The tesside_luas_i value is :"+tesside_luas_i);
System.out.println("The tesside_luas_j value is :"+tesside_luas_j);
answer3 = Double.parseDouble(dij3)/(1 + Math.pow(( Double.parseDouble(tesside_luas_i) / Double.parseDouble(tesside_luas_j) ),0.5847));
String str = String.valueOf( answer3 );
System.out.println("The answer value is :"+str);
url = "/jsp/model/tessideAnswer.jsp";
dispatchErrorMsg( request, response, url, "" );
catch (Exception e)
request.setAttribute("pd.errorMessage", e.getMessage());
dispatchErrorMsg( request, response, "/jsp/Error.jsp", e.getMessage() );
//PotensiPasaran
if (handler != null && !handler.equals( "" ) && handler.equals( "cal2" ))
try
System.out.println("The DIJ2 value is :"+dij2);
System.out.println("The luas_i value is :"+luas_i);
System.out.println("The luas_j value is :"+luas_j);
answer2 = Double.parseDouble(dij2)/(1 + Math.sqrt(( Double.parseDouble(luas_i) / Double.parseDouble(luas_j) )));
System.out.println("The answer value is :"+answer2);
url = "/jsp/model/potensiPasaranAnswer.jsp";
dispatchErrorMsg( request, response, url, "" );
catch (Exception e)
request.setAttribute("pd.errorMessage", e.getMessage());
dispatchErrorMsg( request, response, "/jsp/Error.jsp", e.getMessage() );
//Reilly
if (handler != null && !handler.equals( "" ) && handler.equals( "add" ))
try
System.out.println("The DIJ value is :"+dij);
System.out.println("The population_i value is :"+population_i);
System.out.println("The population_j value is :"+population_j);
answer = Double.parseDouble(dij)/(1 + Math.sqrt(( Double.parseDouble(population_i) / Double.parseDouble(population_j) )));
System.out.println("The answer value is :"+answer);
url = "/jsp/model/reillyAnswer.jsp";
dispatchErrorMsg( request, response, url, "" );
catch (Exception e)
request.setAttribute("pd.errorMessage", e.getMessage());
dispatchErrorMsg( request, response, "/jsp/Error.jsp", e.getMessage() );
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
doPost(request, response);
}//end doGet
public void dispatchErrorMsg(HttpServletRequest req, HttpServletResponse res,
String target, String message)
try
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(target);
req.setAttribute("eshop.ErrMessage",message);
dispatcher.forward(req, res);
catch (Exception e)
System.err.println( e.getMessage() );
}//end class -
Hi,
Can any one tell me how to convert a CLOB into BLOB? In Oracle 10g there is a function which is converttoblob(). But in Oracle 9i there is no function as such. If i am using Hextoraw() function still then its giving some pointer error. please let me know the solution.FUNCTION c2b( c IN CLOB ) RETURN BLOB
-- typecasts CLOB to BLOB (binary conversion)
IS
pos PLS_INTEGER := 1;
buffer RAW( 32767 );
res BLOB;
lob_len PLS_INTEGER := DBMS_LOB.getLength( c );
BEGIN
DBMS_LOB.createTemporary( res, TRUE );
DBMS_LOB.OPEN( res, DBMS_LOB.LOB_ReadWrite );
LOOP
buffer := UTL_RAW.cast_to_raw( DBMS_LOB.SUBSTR( c, 16000, pos ) );
IF UTL_RAW.LENGTH( buffer ) > 0 THEN
DBMS_LOB.writeAppend( res, UTL_RAW.LENGTH( buffer ), buffer );
END IF;
pos := pos + 16000;
EXIT WHEN pos > lob_len;
END LOOP;
RETURN res; -- res is OPEN here
END c2b; -
How to Convert Report into Excel Sheet when Sending Mail.
Dear Friends,
i want to send mail to HOD of Product with an Excel Sheet .
i want to send Pending Issue details to HOD in Excel Sheet attachment .
here i have pending issue report now i need to send it in Excel Sheet attachment .
i have table where i have manage Product ID and HOD OF PRODUCT.
CREATE TABLE "MAP_USER_PRODUCT_DTL"
( "ID" NUMBER NOT NULL ENABLE,
"PRODUCT_ID"NUMBER,
"USER_ID" VARCHAR2(5) NOT NULL ENABLE,
"HOD_PROD" VARCHAR2(100)========================================Value is Y OR N IF HOD then Y else N
CONSTRAINT "MAP_USER_PRODUCT_DTL_PK" PRIMARY KEY ("ID") ENABLE
/i have one more table where all complete issue detail insert.
CREATE TABLE "CRM_ISSUE_PROBLEM"
( "ID" NUMBER,
"SUBJECT" VARCHAR2(255) NOT NULL ENABLE,
"CLIENT_ID" NUMBER,
"ASSIGNED_TO_ID" VARCHAR2(100),
"ASSIGNED_ON" DATE,
"DESCRIPTION" VARCHAR2(4000),
"PRODUCT_ID" NUMBER NOT NULL ENABLE,
"STATUS_ID" NUMBER NOT NULL ENABLE,
CONSTRAINT "CRM_ISSUE_PROBLEM_PK" PRIMARY KEY ("ID") ENABLE
Here STATUS_ID is Like Pending ISsue,Open Issue and Close Issue .i want to send mail to HOD with Pending Issue Report convert into Excel Sheet and send to HOD?
How can i do this.
Thanks
Edited by: Vedant on Oct 12, 2011 12:36 AM
Edited by: Vedant on Oct 12, 2011 2:22 AMHello Vedant,
Would it suffice if you send a CSV file?
If yes, then see following code.. run the code under APEX > Home > SQL Workshop > SQL Commands
DECLARE
ln_id NUMBER;
lc_clob CLOB;
lb_blob BLOB;
li_in PLS_INTEGER := 1;
li_out PLS_INTEGER := 1;
li_lang PLS_INTEGER := 0;
li_warning PLS_INTEGER := 0;
lv_mail_rcpts VARCHAR2(2000) := '[email protected]';
lv_mail_from VARCHAR2(100) := '[email protected]';
lv_clmn_separator VARCHAR2(1) := ',';
BEGIN
-- Build file content as CLOB
-- Replace with your query
FOR i IN (select object_id A, object_name B, object_type C, status D, temporary E, generated F, secondary G,namespace H from user_objects where rownum < 10)
LOOP
IF lc_clob IS NULL THEN
lc_clob := i.A||lv_clmn_separator||i.B||lv_clmn_separator||i.C||lv_clmn_separator||i.D||lv_clmn_separator||i.E||lv_clmn_separator||i.F||lv_clmn_separator||i.G||lv_clmn_separator||i.H;
ELSE
lc_clob := lc_clob||CHR(10)||i.A||lv_clmn_separator||i.B||lv_clmn_separator||i.C||lv_clmn_separator||i.D||lv_clmn_separator||i.E||lv_clmn_separator||i.F||lv_clmn_separator||i.G||lv_clmn_separator||i.H;
END IF;
END LOOP;
-- Convert CLOB to BLOB
DBMS_LOB.CREATETEMPORARY(lb_blob,TRUE);
DBMS_LOB.convertToBlob(lb_blob,lc_clob,DBMS_LOB.LOBMAXSIZE,li_in,li_out,DBMS_LOB.DEFAULT_CSID,li_lang,li_warning);
-- Send mail
ln_id:= APEX_MAIL.SEND(
p_to => lv_mail_rcpts,
p_from => lv_mail_from,
p_subj => 'Subject Goes here',
p_body => 'Body goes here'
-- add CSV file as attachment
APEX_MAIL.ADD_ATTACHMENT
p_mail_id => ln_id,
p_attachment => lb_blob,
p_filename => 'filename.csv',
p_mime_type => 'application/csv'
-- push mail queue
APEX_MAIL.PUSH_QUEUE;
-- empty temporary space
DBMS_LOB.FREETEMPORARY ( lob_loc => lb_blob);
COMMIT;
END;Regards,
Hari -
How to call CLOB to BLOB conversion function within stored procedure?
I have a tiny APEX application from which I need to be able to print. I’ve used these two resources: (Is there an inexpensive APEX report printer for invoices/checks/statements? and http://download.oracle.com/docs/cd/E14373_01/appdev.32/e13363/up_dn_files.htm#CJAHDJDA)
I guess that in order to be able to download the RTF document stored in CLOB, I need to convert it into BLOB. I’ve found this function for this purpose on Oracle forums:
CREATE OR REPLACE FUNCTION c2b( c IN CLOB ) RETURN BLOB
-- typecasts CLOB to BLOB (binary conversion)
IS
pos PLS_INTEGER := 1;
buffer RAW( 32767 );
res BLOB;
lob_len PLS_INTEGER := DBMS_LOB.getLength( c );
BEGIN
DBMS_LOB.createTemporary( res, TRUE );
DBMS_LOB.OPEN( res, DBMS_LOB.LOB_ReadWrite );
LOOP
buffer := UTL_RAW.cast_to_raw( DBMS_LOB.SUBSTR( c, 16000, pos ) );
IF UTL_RAW.LENGTH( buffer ) > 0
THEN
DBMS_LOB.writeAppend( res, UTL_RAW.LENGTH( buffer ), buffer );
END IF;
pos := pos + 16000;
EXIT WHEN pos > lob_len;
END LOOP;
RETURN res; -- res is OPEN here
END c2b;And I am trying to use it in the modified download procedure that I also have found on Oracle forums:
CREATE OR REPLACE PROCEDURE DOWNLOAD_WO(v_id IN NUMBER)
AS
v_mime VARCHAR2(48);
v_length NUMBER;
v_file_name VARCHAR2(2000):= 'WO_Download.rtf';
lob_loc CLOB;
v_blob BLOB;
v_company jobs_vw.company%TYPE;
v_project jobs_vw.project%TYPE;
v_description jobs_vw.description%TYPE;
v_date_ jobs_vw.date_%TYPE;
v_job_no jobs_vw.job_no%TYPE;
v_apqwo jobs_vw.apqwo%TYPE;
-- v_mime VARCHAR2(48) := 'application/msword';
BEGIN
SELECT mime_type, report, DBMS_LOB.GETLENGTH(report)
INTO v_mime,lob_loc,v_length
FROM report_layouts
WHERE rl_id = 22332925279634283;
-- JOB_VW record:
SELECT job_no
,date_
,description
,apqwo
,project
,company
INTO v_job_no
,v_date_
,v_description
,v_apqwo
,v_project
,v_company
FROM jobs_vw
WHERE id = 214;
-- Replace holders with actual values:
lob_loc := REPLACE(lob_loc, '#COMPANY#', v_company);
lob_loc := REPLACE(lob_loc, '#PROJECT#', v_project);
lob_loc := REPLACE(lob_loc, '#DESCRIPTION#', v_description);
lob_loc := REPLACE(lob_loc, '#DATE_#', TO_CHAR(v_date_, 'DD/MM/YYYY'));
lob_loc := REPLACE(lob_loc, '#JOB_NO#', v_job_no);
lob_loc := REPLACE(lob_loc, '#APQWO#', v_apqwo);
-- 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( nvl(v_mime,'application/octet'), FALSE );
-- set the size so the browser knows how much to download
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="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
-- wpg_docload.download_file( Lob_loc );
v_blob := c2b(lob_loc);
wpg_docload.download_file( v_blob );
end DOWNLOAD_WO;
/Unfortunately when I try to compile the download_wo stored procedure I am getting this error:
Error at line 64: PL/SQL: Statement ignoredThe 64th line is:
v_blob := c2b(lob_loc);How should I correctly call c2b within download_wo? Any advice is greatly appreciated.
Thank you for your time.
DanielHello there,
Well, its invalid :(
Object C2B is Invalid. I didn't know since when I run the create ... function, I only get this feedback:
Statement processed.
0.19 secondsI am investigating.
Daniel
Maybe you are looking for
-
Deleteing files on an external hard disk with finder
lately i have been having problems deleting files on external hdd with finder cos the file doesn't appear to be deleted, it deletes them into the ext. hdd pls how do i make finder delete the files permanetely from the drive?
-
10.9.2 Problems with Flash Player?
After updating to 10.9.2 I can no longer continue to work online on my photo book. It work no links on the site. After opening the page I can not even sign off. I am now forced to take the computer to my wife, to continue working there at the photo b
-
QM-Delivery Inspection lot clubbing
Dear Gurus, Is it possible to club the diiferent deliveris in to one inspection lot. For example, presently system creates 1 inspection lot per delivery. If user wants next delivery also linked to previous lot and no need of getting a new lot for the
-
Text Lines to print on Marketing Documents
How do I get line Types of Text to print on the documents? 2005A, SP1
-
Calling urls and receiving urls
Hie I have to do some authorization to an external server which happens in two stages. So in first stage i need to call a url to 3rd part server passing some parameters in the url and the server then in response redirects to user specified url (in pa