I've created as
sql>create table nx (name raw(10));
I actually want to store strings like 'klm' in this column.
sql>insert into nx values ('klm');
ORA-01465: invalid hex number
sql>insert into nx values ('6b6c6d');
'6b6c6d' happen to be the hexadecimal representation of 'klm';
is this the only way i can get this kind of data into a raw column? I'm new to RAW datatype hence the question. Is there some kind of conversion function to which I can pass ('klm') and get the raw equivalent?
If it helps I'm using Oracle8i. And although I've executed sql statements manually, the bulk of the application will executing sql in C++ via ODBC API. Also if I read the data from the C++ application the data gets converted to 'klm' automatically.
thanks to anacedent for the link. i haven't found anything i did not know before. it has provided so far an explanation for what i figured out by trial and error. thanks again.
in response to andrew i actually started out with VARCHAR2 for the column. the background is that this application must support single byte character set fully. For example if the application is running on Windows 2000 and using Norwegian code page 1252 is used. This means that the NLS_LANG must be set WE8ISO8859P1 as the character set (or a suitable superset). Note that the application does not support Unicode and that the data source uses Oracle ODBC driver. For most of the data that the application sends to the database this is good enough. However some of the data entered as strings is encrypted by a third party application. I have no control over what characters are produced by the encryption algorithm. The problem is that in some cases the characters produced by the encryption algorithm are not defined in the character set used by the application and the one specified in NLS_LANG. this causes the the data to be corrupted as the problematic characters are replaced with question marks (or upside down question marks). so I thought i could use RAW instead of VARCHAR2 so that NLS_LANG nor the encryption would pose a constraint.
My original question is due to the fact that I want to minimize changes to the application. I have written C++ code to convert let's say 'klm' to '6b6c6d' before sending the data to the database. I'm sure you'd understand my preference for a solution that requires the least amount of changes in the code. if you or anybody else know of a better way to go about (apart from porting the whole thing to Unicode) i would be grateful for your contributions.
You use the RAW datatype to store binary data or byte strings. For example, a RAW variable might store a sequence of graphics characters or a digitized picture. Raw data is like VARCHAR2 data, except that PL/SQL does not interpret raw data. Likewise, Oracle Net does no character set conversions when you transmit raw data from one system to another.
The RAW datatype takes a required parameter that lets you specify a maximum size up to 32767 bytes. The syntax follows:
You cannot use a symbolic constant or variable to specify the maximum size; you must use an integer literal in the range 1 .. 32767.
The maximum width of a RAW database column is 2000 bytes. So, you cannot insert RAW values longer than 2000 bytes into a RAW column. You can insert any RAW value into a LONG RAW database column because the maximum width of a LONG RAW column is 2**31 bytes. However, you cannot retrieve a value longer than 32767 bytes from a LONG RAW column into a RAW variable.