吴裕雄 python oracle操作数据库(4)
import cx_Oracle
conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")
cursor = conn.cursor()
sql = "insert into dept (deptno,dname,loc) values ('%d','%s','%s')" % (88,'design','beijing')
cursor.execute(sql)
conn.commit()
print('添加成功...')
添加成功...
import cx_Oracle
conn = cx_Oracle.connect("hr/admin@localhost:1521/orcl")
cursor = conn.cursor()
sql = "insert into jobs values ('%s','%s','%d','%d')" % ('PRO','程序员',5000,10000)
cursor.execute(sql)
conn.commit()
print('添加成功...')
添加成功...
sql = """
create table jobs_temp(
job_id varchar2(10) primary key,
job_title varchar2(35) not null,
min_salary number(6),
max_salary number(6))
"""
cursor.execute(sql)
conn.commit()
print('表创建成功...')
表创建成功...
sql = """
insert into jobs_temp
select * from jobs
where jobs.max_salary > 10000
"""
cursor.execute(sql)
conn.commit()
print('添加成功...')
添加成功...
import cx_Oracle
conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")
cursor = conn.cursor()
sql = "update emp set sal=sal*1.2 where job='SALESMAN'"
cursor.execute(sql)
conn.commit()
print('更新成功...')
更新成功...
sql = "update emp set sal=(select avg(sal) from emp where job='SALESMAN') where sal<2000"
cursor.execute(sql)
conn.commit()
print('更新成功...')
更新成功...
import cx_Oracle
conn = cx_Oracle.connect("hr/admin@localhost:1521/orcl")
cursor = conn.cursor()
sql = "delete from jobs where job_id='PRO'"
cursor.execute(sql)
conn.commit()
print('delete成功...')
delete成功...
sql = "truncate table jobs_temp"
cursor.execute(sql)
conn.commit()
print('truncate成功...')
truncate成功...
sql = """insert into jobs_temp values ('DESIGN','设计人员',3000,5000)"""
cursor.execute(sql)
conn.commit()
print('添加成功...')
添加成功...
sql = "truncate table jobs_temp"
cursor.execute(sql)
conn.commit()
print('truncate成功...')
sql = """insert into jobs_temp values ('OFFICE','办公文员',3000,5000)"""
cursor.execute(sql)
print('添加成功...下一步设置了保存点...')
sql = """savepoint sp"""
cursor.execute(sql)
sql = """insert into jobs_temp values ('FINANCE','财务人员',3000,5000)"""
cursor.execute(sql)
print('添加成功...下一步回滚到保存点...')
sql = """rollback to savepoint sp"""
cursor.execute(sql)
conn.commit()
print('提交成功...')
sql = """select * from jobs_temp"""
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)
truncate成功...
添加成功...下一步设置了保存点...
添加成功...下一步回滚到保存点...
提交成功...
('OFFICE', '办公文员', 3000, 5000)
吴裕雄 python oracle操作数据库(4)的更多相关文章
- 吴裕雄 python oracle检索数据(2)
import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...
- 吴裕雄 python oracle子查询的用法(3)
import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...
- 吴裕雄 python oracle检索数据(1)
import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/ORCL")cursor = conn. ...
- Python:操作数据库
(一) 前言 本文说明如何连接Oracle.MySQL.sqlserver,以及执行sql.获取查询结果等. (二) DB-API DB-API阐明一系列所需对象和数据库 ...
- MySQL---连接器(python如何操作数据库媒介,基于python语言)
MySQL — 连接器 连接器的概念 它们往往是一类Python包,或者是一类已经写好的Python库.这些库提供了我们Python去连接数据库服务器的基本功能. 既然它是一个包,那么我们首先学会 ...
- Python连接操作数据库
步骤: 1.创建与数据库的连接对象: 2.创建游标: 3.通过游标执行语句 4.增删改需要提交(commit)数据 5.关闭连接 如: import MySQLdb # Python通过MySQL ...
- python中操作数据库
python中要操作数据库,要使用该数据库在python中对应的驱动库,本文介绍python操作mysql数据库 1.首先安装pymysql 2.导入库 3.建立连接 4.建立游标 5.发起请求 6. ...
- python 连接操作数据库(二)
一.我们接着上期的博客继续对ORM框架进行补充,顺便把paramiko模块也给大家讲解一下: 1.ORM框架: 在连接操作数据库的第一个博客中也已经说了,sqlalchemy是一个ORM框架,总结就是 ...
- python 多线程操作数据库
如果使用多线程操作数据库,容易引起多用户操作锁表 OperationalError: (2013, 'Lost connection to MySQL server during query') 使用 ...
随机推荐
- Android APP打包错误,Could not resolve com.android.tools.lint:lint-gradle:26.1.2.
1.Please select the product flavors to build and sign 不专业的翻译一下(请选择产品的味道来制作和签名)什么鬼: 选中Flavors中的选项即可: ...
- hdfs底层存储分隔符
字段分割 \ map字段里面key \ value \ 每行结尾用linux换行符 \0a '\r'是回车,'\n'是换行,前者使光标到行首,后者使光标下移一格,通常敲一个回车键,即是回车,又是换行( ...
- 零基础学习python_pickle(31课)
上次我提到了对文件的读写等一系列操作,回想下,要想从文件内读取内容无论是read还是readline,读取出来的是不是都是字符串呢?那么如果想让字典.列表这些数据类型保存进文件到读取出来都是原来的类型 ...
- [python] 初学python,级联菜单输出
#Author:shijt china_map = { "河北": { '石家庄': ['辛集', '正定', '晋州'], '邯郸': ['涉县', '魏县', '磁县'], ' ...
- 【Jmeter自学】badboy使用(三)
==================================================================================================== ...
- Failed to execute request because the App-Domain could not be created. Error: 0x80070002 系统找不到指定的文件。
360更新补丁后,网站就打不开aspx文件了,后来一查是framework2.0的KB2844285这个补丁引起的.把它卸载掉就ok了!
- IDEA 快捷操作 Windows
1.查找Action ctrl+shift+A :可通过其查询其他操作快捷键等. 2.项目之间跳转:ctrl+shift+[ 与 ctrl+shift+] 3.alt + 数字 展开对应窗口 4. ...
- 2690036 - SAP HANA 2.0 SPS 03 Database Revision 034
Symptom This is the SAP Release Note for SAP HANA 2.0 Database Revision 034 (2.00.034.00) of the SAP ...
- service和pod通过标签绑定
service和pod绑定 apiVersion: v1 kind: Service metadata: name: my-haproxy labels: app: my-haproxy spec: ...
- 22.Windows及linux下gerapy使用
Windows安装 gerapy1.pip install gerapy2.gerapy init 3.cd gerapy(切换目录到gerapy文件夹)4.gerapy migrate5.gerap ...