Python Forum
Cursor Variable inside Another Cursor . CX_ORacle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cursor Variable inside Another Cursor . CX_ORacle
#1
Hi all,

I have 3 cursors, want to pass values from first and second on third cursor query as below.



import cx_Oracle as oracledb
conn = oracledb.connect("/", mode=oracledb.SYSASM)
cursor_dgnames = conn.cursor()
cursor_dgnames.execute("select distinct name from myview1")
for v_dgnames in cursor_dgnames:
    print(str(v_dgnames[0]))
    v_dgname=str(v_dgnames[0])
    cursor_fgnmaes = conn.cursor()
    cursor_fgnmaes.execute("select distinct fg from myview2 where TYPE<>'XYZ'")
    for v_fgnames in cursor_fgnmaes:
        print(str(v_fgnames[0]))
        v_fgname=str(v_fgnames[0])
        cursormain = conn.cursor()
        cursormain.execute("select d.name from myview3 d, myview4 dg where d.N = dg.N and dg.name=%s and d.F=%s")(v_dgnames,v_fgnames)
I tried different ways but none worked. Anyone could help on this please?
Reply
#2
(Apr-08-2022, 02:41 PM)paulo79 Wrote: I tried different ways but none worked
It is always difficult to judge what exactly did not work. Is the result not what you expected? Did you get an error message?

This does not seem to be correct:
cursormain.execute("select d.name from myview3 d, myview4 dg where d.N = dg.N and dg.name=%s and d.F=%s")(v_dgnames,v_fgnames)
Placehoders in cx_Oracle are a colon and an identifier or a number, as far as I know. And the values should be supplied as a list or a dictionary. Like this:
cursormain.execute("select d.name from myview3 d, myview4 dg where d.N = dg.N and dg.name=:dg and d.F=:df", [v_dgnames,v_fgnames])
Please let me know if this helps.

For reasons of efficiency it would be better to create the three cursors before the for loop. And also note cursors should be closed after use.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with Web Cursor and Chrome Extension Interaction During Web Scraping ScraperHelge 0 460 Mar-26-2025, 03:47 PM
Last Post: ScraperHelge
  not able to call the variable inside the if/elif function mareeswaran 3 535 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  Variable being erased inside of if statement deusablutum 8 2,042 Jun-15-2024, 07:00 PM
Last Post: ndc85430
  Help with cursor in terminal river251 2 1,217 May-23-2024, 10:40 AM
Last Post: perfringo
  Variable definitions inside loop / could be better? gugarciap 2 1,259 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 8,089 Nov-07-2023, 09:49 AM
Last Post: buran
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 4,688 Apr-15-2023, 05:17 PM
Last Post: deanhystad
Question Sqlite3 how to know when cursor.execute didn't return anything ? SpongeB0B 2 1,610 Dec-18-2022, 06:13 PM
Last Post: deanhystad
  Command error - cursor.executemany(comandoSQL,valoresInserir) TecInfo 2 2,528 Nov-18-2022, 01:57 PM
Last Post: TecInfo
  Cursor write 3rd file empty paulo79 3 2,726 Mar-10-2022, 02:51 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020