使用cx_Oracle将CSV文件内容加载到oracle并获取Select关键字错误

时间:2017-08-01 21:17:15

标签: python oracle csv

我正在尝试将csv文件加载到Oracle表中,我收到此错误:

<?php
$get = mysqli_query($conn, "SELECT supplier.*,product.* FROM 
supplier,product ORDER BY supplier.supplierid ASC");
$option = '';
while ($row = mysqli_fetch_array($get, MYSQLI_ASSOC)) {
    $option .= '<option value = "' . $row['productname'] . '">' . 
        $row['suppliername'] . '</option>'; 
}
<label style="margin-left:25px;margin-bottom: 10px; ">Supplier:
</label><select style="margin-bottom:10px ;margin-left: 50px;width: 
200px"> <?php echo $option; ?></select>

以下是我正在使用的代码:

DatabaseError: ORA-00928: missing SELECT keyword

如果我打印行[:1]和行[:2]这是我得到的输出:

def Create_list():
reader = csv.reader(open("Query_result_combined.csv","r"))
lines=[]
for line in reader:
    lines.append(line)
print(lines[:1])
print(lines[:2])
return lines

def Insert_data():
db_user = "XXXXXXX"  # replace this with correct user name
db_password = "********"  # Set the environment variable DB_PASSWORD
db_connection_name = "***********"# repalce this with correct database name
#db_driver = "oracle.jdbc.OracleDriver","C:/Oracle/32bitclient/product/11.2.0/client_1/jdbc/lib/ojdbc6.jar"
print("Connecting Now!!")
con = cx_Oracle.connect(db_user,db_password,db_connection_name)
print("Connected to Oracle!!")
lines=Create_list()
#print lines
cur=con.cursor()
print("Inserting data")
cur.executemany("INSERT INTO BRIODB.A608232_QUERY_RESULT ('InteractionId','QueryId','Score','StartOffsetInMs','EndOffsetInMs','SpeakerRole','QueryIdentity','SpeakerId') VALUES(:1,:2,:3,:4,:5,:6,:7,:8)",lines)
con.commit ()
cur.close()
print("completed")

我无法解决问题。

1 个答案:

答案 0 :(得分:1)

如果表具有大写列名,则删除insert语句列列表中列名周围的'。如果insert语句中列名的大小写与表中的列名匹配,则将'替换为"。后者是您使用特殊字符引用列的方式,或者列名称是混合大小写的情况。