# Can OCI8 format RAW Oracle binary fields in hex

**URL:** <https://www.ruby-forum.com/t/can-oci8-format-raw-oracle-binary-fields-in-hex/119638>\
**Category:** Ruby\
**Created:** [November 8, 2007, 8:42pm UTC](https://www.ruby-forum.com/t/can-oci8-format-raw-oracle-binary-fields-in-hex/119638 "2007-11-08T20:42:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [November 8, 2007, 8:42pm UTC](https://www.ruby-forum.com/t/can-oci8-format-raw-oracle-binary-fields-in-hex/119638/1 "2007-11-08T20:42:51Z")

</div>

I’m using the OCI8 module to dump out Oracle tables. Some of the fields  
are defined as RAW and the dumped data is in binary format. Is there a  
way to have this dumped as HEX? I wouldn’t know which fields would be  
RAW  
so I’m hoping OCI8 is smart enough to detect RAW fields and convert them  
to HEX automatically.

---

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [November 11, 2007, 4:53am UTC](https://www.ruby-forum.com/t/can-oci8-format-raw-oracle-binary-fields-in-hex/119638/2 "2007-11-11T04:53:31Z")

</div>

Hi,

On 11/9/07, Sean N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m using the OCI8 module to dump out Oracle tables. Some of the fields  
> are defined as RAW and the dumped data is in binary format. Is there a  
> way to have this dumped as HEX? I wouldn’t know which fields would be RAW  
> so I’m hoping OCI8 is smart enough to detect RAW fields and convert them  
> to HEX automatically.

1. Change oci8.rb as follows.

## From: (line 860 - 866)

```
  when SQLT_LNG, SQLT_LBI
    datasize = @ctx[OCI8::Util::CTX_LONG_READ_LEN]
  when SQLT_CLOB
    datatype = :nclob if p.attrGet(OCI_ATTR_CHARSET_FORM) == 

```

## SQLCS\_NCHAR end

## To: (line 860 - 868)

```
  when SQLT_LNG, SQLT_LBI
    datasize = @ctx[OCI8::Util::CTX_LONG_READ_LEN]
  when SQLT_CLOB
    datatype = :nclob if p.attrGet(OCI_ATTR_CHARSET_FORM) == 

```

## SQLCS\_NCHAR when SQLT\_BIN datasize \*= 2 if OCI8::BindType::Mapping[OCI8::SQLT\_BIN] == OCI8::BindType::String end

1. Add the following code to your code.

To revert the behavior:  
OCI8::BindType::Mapping[OCI8::SQLT\_BIN] = OCI8::BindType::RAW
