# How Do I Convert a BASE64 String Into Its Native Format?

Salesforce stores the Attachment and ContentVersion bodies as BASE64 strings — a common question is “How can I turn a database Attachment into a file my application can read?”. Since the data is stored as a BASE64 string, this is equivalent to “How do I convert a BASE64 string into its binary equivalent?”.

The answer to this question is database dependent.

## Oracle

To perform BASE64 to binary conversion in Oracle:

* Download the base64decode() function from the [link on oracle-base.com](https://oracle-base.com/dba/script?category=miscellaneous\&file=base64decode.sql).
* Use SQL to convert the body of Attachments to their binary format:
  * `SELECT id, BASE64DECODE(body) AS rawbody FROM Attachment`

You may want to use the BASE64DECODE() function to create a permanent view to the Attachment or ContentVersion table.

## SQL Server

To convert a BASE64 column to a text column in SQL/Server:

```sql
SELECT
    CONVERT(
        VARCHAR(MAX),
        CAST(” AS XML).value(‘xs:base64Binary(sql:column(“Body”))’, ‘VARBINARY(MAX)’)
    ) AS RESULT
FROM
    Attachment
```

To convert a BASE64 column to a binary column in SQL/Server:

```sql
SELECT
    CAST(” AS XML).value(‘xs:base64Binary(sql:column(“Body”))’, ‘VARBINARY(MAX)’)
FROM
    Attachment
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.capstorm.com/frequently-asked-questions/usage/how-do-i-convert-a-base64-string-into-its-native-format.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
