我尝试使用以下代码从Python中的Oracle DB读取:
conn: SqlConnection
# conn_info = DotenvSqlConnection.get_connection_info(add_env_to_connection_id(ConnectionList.Oracle, forced_env_type=EnvironmentType.Dev))
conn_info = conn.get_connection_info(add_env_to_connection_id(ConnectionList.Oracle, forced_env_type=EnvironmentType.Dev))
host_Or= conn_info.host
service_or=conn_info.service
user_id_or=conn_info.user
password_or= conn_info.password
port_or = conn_info.port
print(host_Or, service_or, user_id_or, password_or, port_or)
connection_string = f"{user_id_or}/{password_or}@{host_Or}:{port_or}/{service_or}"
cnxn = cx_Oracle.connect(connection_string)
cursor = cnxn.cursor()
cursor = cnxn.cursor()
table = 'myTable'
account_query = f'''
SELECT a.*
FROM my_user.{table} a
FETCH FIRST 4333 ROWS ONLY
ORDER BY a.ACCNT_ID;
'''
cursor.execute(account_query)
row = cursor.fetchone()
# Print the count value (number of rows)
if row:
row_count = row[0]
print("Number of rows:", row_count)
else:
print("No rows found.")
字符串
但我一直得到以下错误:
----> 9 cursor.execute(account_query)
10 row = cursor.fetchone()
12 # Print the count value (number of rows)
DatabaseError: ORA-00933: SQL command not properly ended
的
我已经尝试了很多方法来解决它,但它不断出现。任何建议将是伟大的感谢!
1条答案
按热度按时间qybjjes11#
尝试重写查询。执行两个步骤:
首先(一般来说),删除终止分号:
字符串
其次,重写查询,使
ORDER BY
排在第一位,FETCH
排在第二位:的