我正在尝试执行这个Python脚本:
import pandas as pd
import numpy as np
import os
import cx_Oracle
import csv
con = cx_Oracle.connect('CIRCU3/CIRCU3@localhost:1521/korcl')
params = {'year': str(2016)}
df = pd.read_sql_query(script_SQL, con, params)
其中script_SQL是:
SELECT
kwhIT AS kwhIT,
kwhCLT AS kwhCLT,
TEMPEXT AS T
FROM T_MEASURES_TE
WHERE
ID_SITE = 21
AND TO_CHAR(TIMESTAMP, 'YYYY') = :year
并返回错误ORA-01008:并非所有变量都绑定。
我无法弄清楚问题出在哪里。谢谢你的帮助。
答案 0 :(得分:2)
参数未正确传递给pandas.read_sql_query()。您需要以下代码:
df = pd.read_sql_query(script_SQL, con, params=params)