I have the following table:
create table o_newstdata1 (
field1 raw(8)
);
the following input.data file:
0x12345678
0x1234
0x12
how can I insert such a data into my o_newstdata1 table?
I've tried to load it as a varchar data:
load data
INFILE '/export/home/mine/input.data'
replace
into table o_newstdata1
trailing nullcols
(
field1 varchar (8)
)
And queried something like this:
select field1 from o_newstdata1 where utl_raw.cast_to_raw(field1) like '0x1234';
but it doesn't work, any suggestions?
There are possibly two sources of errors:
To check if the querying part works, use something like:
You don't need to cast to a raw, you can use Oracle's hex format directly. Version 1 uses implicit conversion from
RAW
TOVARCHAR2
, version 2 explicit conversion:Should the datatype not be specified as RAW?
From the docs:
If your data is not really binary/raw (as indicated by the size of the column), but just a number, you could store it as a number.
Hex is just one way to represent a number (a notation). So I would just store it as a numeric, and put a view on top of it, so you can see/query hex values directly.
This way you could even add or compare these values in the database.