cx_Oracle returning varchar columns with HTML entities
<p>When using cx_Oracle to query a database, I have a a column storing text as varchar2. For some reason, if I have "&lt;" or ">" or characters like those stored in the table, then  when I query the table it replaces those values with their HTML entity equivalent (ex: "&lt;" becomes "&amp;lt;"). For example:</p>

<p>If I have the following data in my table:</p>

<pre><code>ID  | VARCHAR2_DATA
----|-----------------
1   | &lt;span&gt;hi1&lt;/span&gt;
2   | &lt;span&gt;hi2&lt;/span&gt;
</code></pre>

<p>and then I run the following code:</p>

<pre><code>import cx_Oracle
conn = cx_Oracle.connect(DATABASE_CONNECTION_STRING)
cursor = conn.cursor()
cursor.execute("SELECT * FROM TABLE")
ret_data = cursor.fetchall()
</code></pre>

<p>ret_data will contain:</p>

<pre><code>[1, "&amp;lt;span&amp;gt;hi1&amp;lt;/span&amp;gt;"],
[2, "&amp;lt;span&amp;gt;hi2&amp;lt;/span&amp;gt;"]
</code></pre>

<p>Why does this happen? How can I stop it from happening other than iterating through each column/row and doing a find/replace?</p>

<p>You must have some sort of code that is coming between cx_Oracle and your code in order to do this. cx_Oracle returns tuples, not lists, when returning data. As in the following:</p>

<pre><code>[(1, '&lt;span&gt;hi1&lt;/span&gt;'), (2, '&lt;span&gt;hi2&lt;/span&gt;')]
</code></pre>

<p>Try using python at the command prompt without any additional modules being imported. You can check to see what modules are being imported by using the command</p>

<pre><code>python -v
</code></pre>

python oracle cx-oracle