<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: cx_oracle question in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cx-oracle-question/m-p/1317440#M68372</link>
    <description>&lt;P&gt;Where you are referring to df in query2, it's just a string. There's nothing to distinguish df in query 2 as a Pandas dataframe object in memory vs a table named "df" in your Oracle connection. You would need to refer to df in your query as a variable.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;query2 = f"""
    SELECT a.*, b.PODE,b.CODE
    FROM wh.wc201di_06 b
    JOIN {df} a
    ON a.DI_ID = b.DI_ID"""&lt;/LI-CODE&gt;&lt;P&gt;However, I don't use Pandas so I'm not sure how exactly you would go about this. I suspect you would be better off not mixing use of cx_Oracle and Pandas. Either query all the data from your Oracle tables into their own Pandas dataframes and do the &lt;A href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.join.html" target="_self"&gt;joins&lt;/A&gt; and &lt;A href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html" target="_self"&gt;queries&lt;/A&gt; on the dataframes, or build out PL-SQL to do the query solely using cx_Oracle.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Aug 2023 15:46:20 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2023-08-10T15:46:20Z</dc:date>
    <item>
      <title>cx_oracle question</title>
      <link>https://community.esri.com/t5/python-questions/cx-oracle-question/m-p/1317413#M68370</link>
      <description>&lt;PRE&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;cx_Oracle&lt;BR /&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;pandas &lt;SPAN&gt;as &lt;/SPAN&gt;pd&lt;BR /&gt;&lt;BR /&gt;pointer = connection.cursor()&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# part 1&lt;BR /&gt;&lt;/SPAN&gt;query = &lt;SPAN&gt;"""&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;SELECT a.HM_ID, c.DI_ID&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;FROM wh.wc206ng_m_08 a, wh.wc26ng_m_03 b,wh.wc201mb c&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;WHERE a.p_mb_id = b.mb_id&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt; """&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;df = pd.read_sql(query&lt;SPAN&gt;, &lt;/SPAN&gt;connection)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Part 2&lt;BR /&gt;&lt;/SPAN&gt;query2 = &lt;SPAN&gt;"""&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;SELECT a.*, b.PODE,b.CODE&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;FROM wh.wc201di_06 b &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;JOIN df a&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;ON a.DI_ID = b.DI_ID"""&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;df2 = pd.read_sql(query2&lt;SPAN&gt;,&lt;/SPAN&gt;connection)&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(df2)&lt;BR /&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;pointer.close()&lt;BR /&gt;connection.close()&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Connection Closed"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;I keep getting this error message for query 2:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;ORA-00942: table or view does not exist&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Query1 works on its own. I believe I'm getting this error message because Im using the results of query1 in query2. I dont know how to fix this issue.&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 15:01:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cx-oracle-question/m-p/1317413#M68370</guid>
      <dc:creator>V1212</dc:creator>
      <dc:date>2023-08-10T15:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: cx_oracle question</title>
      <link>https://community.esri.com/t5/python-questions/cx-oracle-question/m-p/1317440#M68372</link>
      <description>&lt;P&gt;Where you are referring to df in query2, it's just a string. There's nothing to distinguish df in query 2 as a Pandas dataframe object in memory vs a table named "df" in your Oracle connection. You would need to refer to df in your query as a variable.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;query2 = f"""
    SELECT a.*, b.PODE,b.CODE
    FROM wh.wc201di_06 b
    JOIN {df} a
    ON a.DI_ID = b.DI_ID"""&lt;/LI-CODE&gt;&lt;P&gt;However, I don't use Pandas so I'm not sure how exactly you would go about this. I suspect you would be better off not mixing use of cx_Oracle and Pandas. Either query all the data from your Oracle tables into their own Pandas dataframes and do the &lt;A href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.join.html" target="_self"&gt;joins&lt;/A&gt; and &lt;A href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html" target="_self"&gt;queries&lt;/A&gt; on the dataframes, or build out PL-SQL to do the query solely using cx_Oracle.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 15:46:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cx-oracle-question/m-p/1317440#M68372</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-08-10T15:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: cx_oracle question</title>
      <link>https://community.esri.com/t5/python-questions/cx-oracle-question/m-p/1317816#M68377</link>
      <description>&lt;P&gt;You could nest the first query into the second in sql fashion-&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Part 2
query2 = """
SELECT a.*, b.PODE, b.CODE
FROM wh.wc201di_06 b 
JOIN (SELECT c.HM_ID, e.DI_ID
FROM wh.wc206ng_m_08 c, wh.wc26ng_m_03 d, wh.wc201mb e
WHERE c.p_mb_id = d.mb_id) a
ON a.DI_ID = b.DI_ID"""

df2 = pd.read_sql(query2,connection)
print(df2)&lt;/LI-CODE&gt;&lt;P&gt;As written, the sql engine would try to find whatever the df value is within the database tables set in the oracle connection. If the nesting statements doesn't work, try reading both queries into pandas and then merge like &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt; mentions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 11:55:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cx-oracle-question/m-p/1317816#M68377</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-08-11T11:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: cx_oracle question</title>
      <link>https://community.esri.com/t5/python-questions/cx-oracle-question/m-p/1319134#M68427</link>
      <description>&lt;P&gt;Thanks, I was able to use nesting and common table expression to get a working script.&amp;nbsp;&lt;/P&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;</description>
      <pubDate>Wed, 16 Aug 2023 14:43:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cx-oracle-question/m-p/1319134#M68427</guid>
      <dc:creator>V1212</dc:creator>
      <dc:date>2023-08-16T14:43:20Z</dc:date>
    </item>
  </channel>
</rss>

