convert hex file to binary/raw file
A reader, November 11, 2003 - 3:48 pm UTC
Hi
There was this developer in our company who wrote some perl program to convert jpeg files into hexadecimal files then using utl_file.get_line concatenate line by line and store as a raw variable and store as BLOB (using dbms_lob.write) in the database. It stinks but I am not allowed to change the whole process, the perl program is untouchble.
So my question is, is there a way to convert in a more efficient way a hex file into binary/raw format instead of concatenating line after line...?
November 12, 2003 - 6:39 am UTC
you don't need to concat, you can
loop
read varchar2 string
assign to raw (will auto-convert hex to raw)
dbms_lob.writeAppend
reset raw variable to zero
A reader, November 11, 2003 - 6:13 pm UTC
Hi
If a variable is of type RAW and it's value is increased inside a loop is there anyway to reset it to zero after X loop iterations?
November 12, 2003 - 6:56 am UTC
huh?
what do you mean by "zero" with regards to a "raw"?
Fun with Raws
Dan Clamage, November 12, 2003 - 2:47 pm UTC
declare
v_raw raw(4000);
begin
for i in 0 .. 255 loop
v_raw := v_raw || utl_raw.cast_to_raw(chr(i));
-- equivalent expression without || operator
-- v_raw := utl_raw.concat(v_raw, utl_raw.cast_to_raw(chr(i)));
end loop;
for i in 1 .. utl_raw.length(v_raw) loop
dbms_output.put_line('raw(' || i || ')=[' ||
utl_raw.substr(v_raw, i, 1) || ']');
end loop;
end;
/
raw(1)=[00]
raw(2)=[01]
raw(3)=[02]
...
raw(254)=[FD]
raw(255)=[FE]
raw(256)=[FF]
Hexadecimal
Eva, November 18, 2003 - 5:05 pm UTC
This was somewhat helpful. It gave me some idea.
What I want to do is how I can save my file in .txt
and then covert my string data-characters and numbers
to hexidecimal. I can't seem to find a pl/sql script that
does it or what I need to write this script.
Any guidance would be helpful.
November 21, 2003 - 11:09 am UTC
utl_file is the tool for plsql to write files.
numbers can be converted to hex using "to_char( number, 'XXXXXXX' )"
strings via:
hex_string := utl_raw.cast_to_raw( orig_string );
make sure hex_string is 2x as long as orig_string!!!
Conversion HEX to RAW and RAW to hex
Vikas Sharma, November 19, 2003 - 8:56 pm UTC
Hi Tom,
I have a table which store a binary file content(ms word doc file ) in a blob column. The data is inserted by using LOADFROMFILE of dbms_lob.
I am reading the blob in chunks of 57 using dbms_lob.substr which return the raw data. then i writes it to a text file hex. I use the utl_file.put_line to write file. when a raw data is assign to varchar2 variable it automatically get converted to hex. Am I right? So my text file is writen in hex. Pl correct me if worng.
Now i run a utilities available on internet hex2bin.exe and bin2hex.exe to perform conversion. these utility works fine when i convert a doc file to hex using bin2hex.exe and then again hex2bin.exe i get the same back. But does not work well with the file created by using oracle UTL_FILE. and does not create the binary file (doc file).
When i load the same doc file to database and write a hex file using utl_file and compare the hex file create by utl_file and bin2hex.exe utility. They are different.
Why the 2 file are differernt Does the automatic conversion from raw to varchar of utl_file generate different HEX data.
I am not able tounderstand this behaviour.
Actually my requirment is to display the data ie file store in the database on client FORM6i. The only way suggested by oracle metalink, is read from database write a text file(in hex) at client using text_io then run a utility to convert it to binary file back at client so that way your file is transfer from database to client. then you can open it on client using host cammand..
Any kind of help or suggestions will be higly appreciated.
Thanks,
Reagrds
Vikas Sharma
November 21, 2003 - 3:34 pm UTC
assign a raw to a string and you have hex, yes.
utl_file has a 32k limit on a line length. you are injecting (and have no way not to) a linefeed in there.
if you can use the web, we can do this trivially with iAS and mod_plsql. a simple URL would retreive the document.
Thanks
vikas Sharma, November 24, 2003 - 7:50 pm UTC
Hi Tom,
Thanks,
Regards
Vikas Sharma
Ram, July 07, 2005 - 9:27 am UTC
Tom,
Could you let mw know how find the NOT value of a HEXADECIMAL value in SQL Query ?
Thanks and regards,
Ram
July 07, 2005 - 9:52 am UTC
the "NOT" value?
Ram, July 07, 2005 - 10:25 am UTC
I wanted to find the NOT of HEXADECIMAL value "AAA"
The NOT for Hexadecimal value "AAA" is "FFFFF555".
I need to achieve the same in a SQL Query.
July 07, 2005 - 12:58 pm UTC
1 select to_char(4294967295-to_number('AAA','XXXXXXXX'),'fmXXXXXXXX')
2* from dual
ops$tkyte@ORA10G> /
TO_CHAR(4
---------
FFFFF555
Ram, July 08, 2005 - 2:33 am UTC
Excellent Tom !
Thank you very much !
Best regards,
Ram.