gpt4 book ai didi

python - 如何从 python 将空小数/日期时间插入 MYSQL?

转载 作者:行者123 更新时间:2023-11-29 05:36:32 25 4
gpt4 key购买 nike

我有数据文件:

'Laura', 'Laura Ellenburg', '5342 Picklied Trout Lane', 'Nashville', 'TN',
'38010','2000-02-22', ' ', '454-56-768'

注意结尾附近的 ' '。

我正在使用 python 代码:

  data = []
infile = open ("./BIGPVFC-ASC10e/Employee.asc", "r")
for line in infile:
line = line.rstrip("\n")
line = line.strip()
seq = line.split(", ")
for i in range(0,9):
seq[i] = seq[i].strip("'")
seq = tuple (seq)
data.append(seq)
infile.close()

cursor.executemany ("""insert into PV_employee
(employeeid, employeename, employeeaddress, employeecity, employeestate,
employeezip, employeedatehired, employeebirthdate, employeesupervisor)
values (%s, %s, %s, %s, %s, %s, %s, %s, %s)""", data)

我的表是:

create table PV_employee
(employeeid varchar(10) not null
,employeename varchar(25) null
,employeeaddress varchar(30) null
,employeecity varchar(20) null
,employeestate char(2) null
,employeezip varchar(10) null
,employeedatehired datetime null
,employeebirthdate datetime null
,employeesupervisor varchar(10) null
,primary key (employeeid)
);

我收到错误“警告:列 ..... 的值超出范围”

在空小数的情况下,我得到“警告:不正确的十进制值:列的''......”

我已尝试将 ' ' 更改为 '''NULL'NULL。这些似乎都不起作用。有什么建议吗?

最佳答案

SQL NULL 的 Python 等价物是 None

关于python - 如何从 python 将空小数/日期时间插入 MYSQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10068522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com