我试图从两个不同的表创建一个视图,但是我想用bind变量过滤放置在视图中的结果。
这就是我所做的:
dsn_test = cx_Oracle.makedsn(host='xxxxxx',port='1521',service_name='trtdiag')
con_test = cx_Oracle.connect(user='rtdiag', password='xxxxx',dsn=dsn_test)
cursor = con_test.cursor()
query = '''
CREATE OR REPLACE VIEW INFOS_VEHICLE AS
SELECT IPC_PRESENCE.VEHICLE_ID,IPC_PRESENCE.PRESENT_IWLAN,IPC_PRESENCE.PRESENT_2G3G,RT_SVOI.LAST_SVOI,RT_SVOI.ASSIGNED_DEPOT
FROM IPC_PRESENCE,RT_SVOI
WHERE (IPC_PRESENCE.VEHICLE_ID = RT_SVOI.VEHICLE_ID)
AND (IPC_PRESENCE.VEHICLE_ID = :vehicle)'''
create_view = cursor.execute (query,vehicle=8104)
Cx_oracle引发以下错误:
Traceback (most recent call last):
File "test_view.py", line 15, in <module>
create_view = cursor.execute (query,vehicle=8104)
cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
我的问题:是否可以通过这种方式创建具有绑定变量的视图,还是应该执行一个过程?
答案 0 :(得分:0)
不幸的是,并非不可能。相反,您将创建不带last子句的视图,然后在代码中执行以下操作:
cursor.execute("select * from infos_vehicle where vehicle_id = :vehicle",
vehicle=8104)