发布于2019-09-06 12:10 阅读(2587) 评论(0) 点赞(18) 收藏(4)
代码如下:
sql = 'insert into equipment (order_id, equip_id, name, model, specification, purchase_date, unit_price, owner, owner_department, address, status) values (%s, %s, %s, %s, %s, %s, %f, %s, %s, %s, %s)'
val = ('', '19960100', '生化培养箱', 'LRH--250A', '*', datetime.datetime(1997, 7, 1, 0, 0), 6444.0, 'xx', '创新实验室', '医药楼2-112', '在用')
try:
conn = pymysql.connect(host='127.0.0.1',
port=3306,
user='root',
password='xxxx',
db='assets',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
with conn.cursor() as cursor:
cursor.execute(sql, val)
conn.commit()
except Exception as e:
print(e)
finally:
conn.close()
unit_price数据库中类型的是float,但是每次插入的时候总是提示must be real number, not str,这个是为啥呢?是不是pymysql会自动转换数字成字符串?
作者:python是我的菜
链接:https://www.pythonheidong.com/blog/article/98407/460209a7190423042aee/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!