cx-oracle

CX_Oracle - import data from Oracle to Pandas dataframe

陌路散爱 提交于 2019-12-09 04:51:54
问题 Hy, I'm new in python and I want import some data from a Oracle Database to python (pandas dataframe) using this simple query SELECT* FROM TRANSACTION WHERE DIA_DAT >=to_date('15.02.28 00:00:00', 'YY.MM.DD HH24:MI:SS') AND (locations <> 'PUERTO RICO' OR locations <> 'JAPAN') AND CITY='LONDON' What I did import cx_Oracle ip = 'XX.XX.X.XXX' port = YYYY SID = 'DW' dsn_tns = cx_Oracle.makedsn(ip, port, SID) connection = cx_Oracle.connect('BA', 'PASSWORD', dsn_tns) df_ora = pd.read_sql('SELECT*

Idle database connections in Django

旧街凉风 提交于 2019-12-08 12:52:29
In Django, how do I make my code recover from a database connection which is dead ? This is the scenario: # requests enters view handler # executes code which does some synchronous tasks without any database interaction for 15min. # first database activity in this request after 15min. try: o, created = act_details.objects.get_or_create(id=1) # this line fails because of a dead database connection. except Exception as e: logger.error(e) # ORA-03114: not connected to ORACLE Assuming I handle the exception, is there a way to put things back on track by creating a new database connection in the

How to handle unicode data in cx_Oracle and python 2.7?

有些话、适合烂在心里 提交于 2019-12-08 06:15:24
问题 I am using Python 2.7 cx_Oracle 6.0.2 I am doing something like this in my code import cx_Oracle connection_string = "%s:%s/%s" % ("192.168.8.168", "1521", "xe") connection = cx_Oracle.connect("system", "oracle", connection_string) cur = connection.cursor() print "Connection Version: {}".format(connection.version) query = "select *from product_information" cur.execute(query) result = cur.fetchone() print result I got the output like this Connection Version: 11.2.0.2.0 (1, u'????????????',

Idle database connections in Django

南楼画角 提交于 2019-12-08 03:33:23
问题 In Django, how do I make my code recover from a database connection which is dead ? This is the scenario: # requests enters view handler # executes code which does some synchronous tasks without any database interaction for 15min. # first database activity in this request after 15min. try: o, created = act_details.objects.get_or_create(id=1) # this line fails because of a dead database connection. except Exception as e: logger.error(e) # ORA-03114: not connected to ORACLE Assuming I handle

cx_Oracle And User Defined Types

痴心易碎 提交于 2019-12-08 03:00:17
问题 Does anyone know an easier way to work with user defined types in Oracle using cx_Oracle? For example, if I have these two types: CREATE type my_type as object( component varchar2(30) ,key varchar2(100) ,value varchar2(4000)) / CREATE type my_type_tab as table of my_type / And then a procedure in package my_package as follows: PROCEDURE my_procedure (param in my_type_tab); To execute the procedure in PL/SQL I can do something like this: declare l_parms my_type_tab; l_cnt pls_integer; begin l

Importing from Oracle using the correct encoding with Python

天涯浪子 提交于 2019-12-07 23:49:26
问题 I apologize for making a character encoding question since I know you folk get many everyday, but I couldn't figure out my problem so I asked anyway. Here is what we are doing: Take Data from an Oracle DB using Python and cx_Oracle . Write the data to a file using Python. Ingest the file into Postgres using Python and psycopg2 . Here are the important Oracle settings: SQL> select * from NLS_DATABASE_PARAMETERS; PARAMETER VALUE ------------------------------ -----------------------------------

How do I get cx_Oracle to work on 64-bit Itanium Windows?

巧了我就是萌 提交于 2019-12-07 12:58:06
问题 I'm running Windows Server 2003 on a 64-bit Itanium server which is also running 64-bit Oracle 10.2, and I'd like to install cx_Oracle for Python 2.5. I've used cx_Oracle before many times on both Windows and Linux, and I've also compiled it before on 32 bit versions of those platforms, but I've never tried an IA64 compile. None of the binary builds of cx_Oracle at http://cx-oracle.sourceforge.net/ are 64 bit, and I get an error after installing any of them when trying to run import cx_Oracle

cx_Oracle 'ORA-01843: not a valid month' with unicode parameter

不打扰是莪最后的温柔 提交于 2019-12-07 06:52:07
问题 I have the following: (using ipython) In [30]: con = cx_Oracle.connect('refill_test02/******@MYDB') In [31]: cur = con.cursor() In [32]: cur.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") In [33]: cur.execute("select to_date(:0), to_timestamp(:1) from dual", ['2013-03-12', '2013-03-12 08:22:31.332144']) Out[33]: <__builtin__.OracleCursor on <cx_Oracle.Connection to refill_test02@MYDB>> In [34]: cur.fetchall() Out[34]: [

Inserting a CLOB using cx_Oracle

孤人 提交于 2019-12-07 06:47:24
问题 I am trying to insert a CLOB using the following code. cursor = connection.cursor() cursor.setinputsizes(HERP = cx_Oracle.CLOB) cursor.execute("INSERT INTO myTable (FOO, BAR) VALUES (:FOO, :BAR)", FOO=val1, BAR=val2) cursor.execute("INSERT INTO myTable2 (HERP) VALUES (:HERP)", HERP=val3) #len(HERP) 39097 When I run the script WITHOUT cursor.setinputsizes(HERP = cx_Oracle.CLOB) it fails on the second query WITH ValueError: string data too large , when I run the script with cursor.setinputsizes

sqlalchemy fails to connect but cx_oracle succeeds

笑着哭i 提交于 2019-12-06 21:53:28
I'm attempting to connect to an oracle server in Python. I have this working in cx_Oracle, but when I try to connect using sqlalchemy it fails. The cx_Oracle code: import cx_Oracle import pandas as pd cx_connection = cx_Oracle.connect(user+'/' + pw + '@' + host + ':' + port + '/' + db) df = pd.read_sql(my_query, cx_connection) Executes and returns data from the database based on the query as expected. If I try the same connection with sqlalchemy: import sqlalchemy engine = sqlalchemy.create_engine('oracle+cx_oracle://' + user + ':' + pw + '@' + host + ':' + port + '/' + db) sqlalchemy