Now i use cx_oracle with python to execute oracle statements. I have oracle CDB and PDBs. I need to execute this statement from CDB to PDB (MYPDB)
ALTER SESSION SET CONTAINER=MYPDB;
SELECT (SELECT instance_name FROM v$instance) as CDB_NAME, (SELECT SYS_CONTEXT(‘USERENV’, ‘CON_NAME’) FROM dual) as PDB_NAME ,a.owner ,a.table_name ,a.column_name ,b.comments FROM dba_tab_columns a LEFT JOIN dba_col_comments b ON a.owner = b.owner AND a.table_name = b.table_name AND a.column_name = b.column_name WHERE a.OWNER LIKE ‘USR_%’ ORDER BY a.owner, a.table_name, a.column_name ASC
It works in sql developer but not in cx_oracle. My script is:
conn = cx_Oracle.connect(user=self.user, password=self.password, dsn=self.connection_string)
cursor = conn.cursor()
cursor.execute(“””alter session set CONTAINER=PB24
SELECT a.owner, a.table_name, b.comments FROM dba_tables a LEFT JOIN dba_tab_comments b ON a.owner = b.owner AND a.table_name = b.table_name WHERE a.OWNER LIKE ‘USR_%’ ORDER BY a.owner, a.table_name ASC;
“””)
and return ORA-00922: missing or invalid option
Python version: 3.10.14
Oracle version: 18g
cx_version: 8 latest
Exe Carballeda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.