Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to store bit data in VARCHAR(4000) field?

795389Sep 2 2010 — edited Oct 11 2010
Hi.

Please help!

We are porting some C/C++ software with embedded SQLs from NT/DB2 to Linux/Oracle.
On NT/DB2 we have some table to store file data in a VARCHAR(4000) blocks.
Table looks like this

CREATE TABLE FileData (filetime as timestamp not null, idx int not null, datablock varchar(4000) FOR BIT DATA not null, primary key (filetime, idx) );

As you can see DB2 has appropriate field modifier - "FOR BIT DATA" which makes DB2 storing data as-is, not converting characters.

I need to know - if it is possible to do the same in Oracle like in DB2?
If Oracle has some kind of field modifier like "FOR BIT DATA" in DB2?
If not, how can I do the same in Oracle?

The current problems are:
1) when application imports the file with some national chars the Oracle stores "?" in a database in place of national chars.
2) another piece of a problem - if file is more than 4000 bytes length, it reports the ORA-01461 error (see it is trying to expand some chars to UTF8 char which is not fit a single char, so finally - not fit the field size).
So, it seems that it cannot proceed national chars at all. :-\

For details please see enclosed [C code|http://dmitry-bond.spaces.live.com/blog/cns!D4095215C101CECE!1606.entry] , there is example how data written to a table.
In other places we also need to read data from FIELDATA table and store back to file (other filename, other location).

Here is summary on a field-datatype variants I have tried for the "datablock" field:
1) VARCHAR2, RAW, LONG RAW, BLOB - does not work! All reports the same error - ORA-01461.
2) CLOB, LONG - both working fine but(!) both still returns "?" instead of national chars on data reading.
Hint: how I did try these field types - I just drop the "FileData" table, created it using different type for "datablock" field and run the same application to test it.

I think I need to explain what the problem - we do not provide direct access to Oracle database, we use a some middle-ware. Middle-ware is a C/C++ software which also has a interface for dynamic SQLs execution. So, exactly this middle-ware (which is typically running on the same server with Oracle) receives the "?" instead of national chars! But we need it to return all data AS-IS(!) without any changes!!! That is wjhy I did ask - if Oracle has any options to store byte-data as-is?
The BIG QUESTION - HOW CAN WE DO THIS?!

Another thing I need to explain - it is ok to use Oracle-specific SQL ONLY IF THERE IS REALLY NO WAY TO ACHIEVE THIS WITH STANDARD SQL! Please.
So, please look on a C code (by link I have posted above) and tell - if it is possible to make working in Oracle the VARCHAR approach we using at the moment?
If not - please describe what options do we have for Oracle?


Regards,
Dmitry.

PS. it is Oracle 11gR2 on CentOS 5.4, all stuff installed with default settings, so Oracle db encoding is "AL32UTF8".
C/C++ application is built as ANSI/ASCII application (non-unicode), so sizeof(char)=1.
The target Oracle db (I mean - the one which will be used on customer site) is Oracle 10g. So, solution need to be working on Oracle 10g.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 8 2010
Added on Sep 2 2010
8 comments
1,763 views