cx-oracle

How to access tables from a different schema in oracle 11g using django?

戏子无情 提交于 2021-01-29 09:46:36
问题 I have a user named mi_abc in oracle 11g. The user do not have any table in the database but has access to all the tables in another schema sch_abc. When I run a normal select query from sqldeveloper on the sch_abc schema from mi_abc, it works perfectly fine, but when I use django, I am always getting the error:- django.db.utils.DatabaseError: ORA-00942: table or view does not exist I tried to set the db_table = sch_abc.tableName and also set db_table = tableName but both gives me the same

getting proper date format from SQL search results (datetime.datetime)

烂漫一生 提交于 2021-01-28 11:57:34
问题 This is my first time using cx_oracle. Part of my project is to create a search engine that processes "SELECT FROM.." queries and displays them. This is for searching patient information and the tests he/she have been prescribed. I thought it would also be a good idea to return prescribe dates for tests. Here is what I execute: searchPatientName = "SELECT b.PATIENT_NO, a.NAME, c.TEST_NAME, b.TEST_DATE, b.RESULT FROM patient a, test_record b, test_type c WHERE b.TYPE_ID = c.TYPE_ID AND b

How to use cx_Oracle session pool with Flask gracefuly?

我是研究僧i 提交于 2021-01-28 11:33:09
问题 I'm a newbie to Python and Flask, and I use Oracle, when learning Flask tutorial, I code as follow, but it smells really bad, please help me with these questions, thanks a lot! 1) need I release connection to poll explicitly? 2) how can I implement poll acquire and release gracefully? def get_dbpool(): if not hasattr(g, 'db_pool'): g.dbPool = connect_db() return g.dbPool @app.teardown_appcontext def close_db(error): if hasattr(g, 'db_pool'): g.dbPool.close() @app.route('/') def hello_world():

cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurred

依然范特西╮ 提交于 2021-01-28 11:11:53
问题 I am getting cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurred error while connecting oracle from python. I have installed python 3.7.0 and instantclient_11_2. Below are the process i am doing, import cx_Oracle dsn_tns = cx_Oracle.makedsn( '<ip>', 1521, service_name = '<given service name>') connection = cx_Oracle.connect('user', 'pwd', dsn_tns) I have set system veriable PATH where oci.dll is present. What could be wrong? 回答1: Try: connection = cx_Oracle.connect('user', 'pwd',

Unresponsive requests- understanding the bottleneck (Flask + Oracle + Gunicorn)

[亡魂溺海] 提交于 2021-01-28 08:03:50
问题 I'm new to Flask/Gunicorn and have a very basic understanding of SQL. I have a Flask app that connects to a remote oracle database with cx_oracle. Depending on the app route selected, it runs one of two queries. I run the app using gunicorn -w 4 flask:app . The first query is a simple query on a table with ~70000 rows and is very responsive. The second one is more complex, and queries several tables, one of which contains ~150 million rows. Through sprinkling print statements around, I notice

PYSPARK: CX_ORACLE.InterfaceError: not a query

混江龙づ霸主 提交于 2021-01-27 13:57:24
问题 i need to perform update query in spark job. i am trying below code. but facing issues. import cx_Oracle def query(sql): connection = cx_Oracle.connect("username/password@s<url>/db") cursor = connection.cursor() cursor.execute(sql) result = cursor.fetchall() return result v = [10] rdd = sc.parallelize(v).coalesce(1) rdd.foreachPartition(lambda x : [query("UPDATE db.tableSET MAPPERS ="+str(i)+" WHERE TABLE_NAME = 'table_name'") for i in x]) when i execute the above process i am getting below

How do I pass multiple parameters via pd.read_sql, one singular and another in list format?

五迷三道 提交于 2021-01-25 03:55:17
问题 I have raw data as: id = 2345 id_num = 3,6,343,32 I need to pass both the above as parameters in an ORACLE SQL query via a cx_Oracle connection as: query = “”” select * from mytable where pid = 2345 and id_num in (3,6,343,32) “”” I am creating a dictionary as: sparm = {} sparm['pid'] = id sparm['idnum'] = id_num and trying to use it as: query = “”” select * from mytable where pid = :pid and id_num in :idnum “”” df = pd.read_sql(query, con=conct, params=sparm) without success. The :pid works

How to export a table to csv or excel format

血红的双手。 提交于 2021-01-02 05:25:15
问题 I need to export a oracle table to a csv/excel file format (along with the column headings). A solution through cx_oracle or through sqlplus welcome. Python code from the comment: con = cx.connect() cur = con.cursor() printer = cur.execute(sqlcode) con.commit() 回答1: perhaps use csv module (from standard library): import csv cursor = connection.cursor() # assuming you know how to connect to your oracle db cursor.execute('select * from table_you_want_to_turn_to_csv') with open('output_file.csv'

How to export a table to csv or excel format

落爺英雄遲暮 提交于 2021-01-02 05:23:04
问题 I need to export a oracle table to a csv/excel file format (along with the column headings). A solution through cx_oracle or through sqlplus welcome. Python code from the comment: con = cx.connect() cur = con.cursor() printer = cur.execute(sqlcode) con.commit() 回答1: perhaps use csv module (from standard library): import csv cursor = connection.cursor() # assuming you know how to connect to your oracle db cursor.execute('select * from table_you_want_to_turn_to_csv') with open('output_file.csv'