Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2004
    Location
    Reading
    Posts
    8

    Unanswered: How does the RAW datatype work?

    Hi all.

    I've created as
    sql>create table nx (name raw(10));

    I actually want to store strings like 'klm' in this column.

    using this
    sql>insert into nx values ('klm');

    i get
    ORA-01465: invalid hex number

    using
    sql>insert into nx values ('6b6c6d');

    works.

    '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 for any contribution.

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Read The Fine Manuals at http://tahiti.oracle.com to learn all about RAW datatypes and associated functions.

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: How does the RAW datatype work?

    But if you want to store strings, why would you use RAW? RAW is for binary data about which Oracle knows nothing.

  4. #4
    Join Date
    Jan 2004
    Location
    Reading
    Posts
    8
    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.

    Nelo

  5. #5
    Join Date
    Jan 2004
    Location
    Venezuela
    Posts
    151

    Re: How does the RAW datatype work?

    RAW
    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:

    RAW(maximum_size)


    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.

    http://download-west.oracle.com/docs...ypes.htm#10763
    Joel Pérez

  6. #6
    Join Date
    Jan 2004
    Location
    Reading
    Posts
    8
    thanks joel.

    can you or anybody else give me sql examples for inserts and updates on RAW columns?

    Thanks.

  7. #7
    Join Date
    Jan 2004
    Location
    Venezuela
    Posts
    151
    Originally posted by Nelo
    thanks joel.

    can you or anybody else give me sql examples for inserts and updates on RAW columns?

    Thanks.
    In order to carry out an example with RAW DATATYPES you have to have an interface as PSP , Forms , JSP or something like that to load binary information ( JPEG's, .DOC files, etc).
    Joel Pérez

  8. #8
    Join Date
    Sep 2003
    Location
    Milan, Italy
    Posts
    130
    Originally posted by Nelo
    can you or anybody else give me sql examples for inserts and updates on RAW columns?
    SQL> create table tt (c raw(100));

    Table created.

    SQL> insert into tt (c) values (hextoraw ('CAFEBABE'));

    1 row created.

    SQL> select * from tt;

    C
    ----------------------------------------------------------
    CAFEBABE

    SQL> select * from tt where c = hextoraw ('CAFEBABE');

    C
    ----------------------------------------------------------
    CAFEBABE

    SQL> select * from tt where c = hextoraw ('AA');

    no rows selected

    SQL> update tt set c = hextoraw ('ABBA');

    1 row updated.

    SQL> select * from tt;

    C
    --------------------------------------------------------
    ABBA

    HTH
    Al

    PS Obviously all literals are in hexadecimal (base-16).

  9. #9
    Join Date
    Mar 2012
    Posts
    1

    raw datatype

    I want to store a sound file in a field which is raw type.
    can you please give me an example how to insert a record.

  10. #10
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    do not hijack a 9 year old thread. Start your own new one.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •