执行自定义SQL语言:

from django.db import connection
​
cursor=connection.cursor()
​
# 插入操作
cursor.execute("insert into hello_author(name) values('传说中的申小五')")
​
# 更新操作
cursor.execute("update hello_author set name='abc' where name='bcd'")
​
# 删除操作
cursor.execute("delete from hello_author where name='abc'")
​
# 查询操作
cursor.execute("select * from hello_author")
​
raw=cursor.fetchone()  # 返回结果行游标直读向前,读取一条
cursor.fetchall()  # 读取所有

 



相关文章:

  • 2019-08-01
  • 2021-11-18
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-02
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
相关资源
相似解决方案