[英]SQLite3 OperationalError: near “(”: syntax error
I have looked everywhere and cannot figure out why this is not working.我到处看了看,无法弄清楚为什么这不起作用。
import sqlite3
path = '/Users/...'
con = sqlite3.connect(path+'YSD.sqlite')
cur = con.cursor()
cmd = 'SELECT ISD_NAME replace(ISD_NAME,"Statewide"," Statewide") FROM enr'
cur.execute(cmd)
con.commit()
con.close()
OperationalError: near "(": syntax error
I have also tried this, to no avail:我也试过这个,无济于事:
cmd = 'SELECT ISD_NAME replace(ISD_NAME,?,?) FROM enr'
cur.execute(cmd, ("\"Statewide\"","\" Statewide\""))
If your intent is to fetch ISD_NAME
column values and replace "Statewide" with " Statewide" remove ISD_NAME
after SELECT
statement.如果您的意图是获取ISD_NAME
列值并将“Statewide”替换为“Statewide ” ,请在SELECT
语句之后删除ISD_NAME
。
For instance, assuming you have a table like this:例如,假设你有一个这样的表:
CREATE TABLE enr("id" PRIMARY KEY, "ISD_NAME" VARCHAR);
INSERT INTO enr VALUES (1, "somethingStatewide");
Your script becomes:你的脚本变成:
cmd = 'SELECT replace(ISD_NAME,"Statewide"," Statewide") FROM enr'
cur.execute(cmd)
Test with print:打印测试:
records = cur.fetchall()
print(records)
Here the result:结果如下:
[(u'something Statewide',)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.