吴裕雄 python oracle操作数据库
Posted 天生自然
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了吴裕雄 python oracle操作数据库相关的知识,希望对你有一定的参考价值。
import cx_Oracle
conn = cx_Oracle.connect("scott/[email protected]: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/[email protected]: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/[email protected]: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/[email protected]: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操作数据库的主要内容,如果未能解决你的问题,请参考以下文章
吴裕雄 python 神经网络——TensorFlow 数据集高层操作
吴裕雄--天生自然 PYTHON语言数据分析:ESA的火星快车操作数据集分析
吴裕雄 python 神经网络——TensorFlow 队列操作
吴裕雄 python 神经网络——TensorFlow 多线程队列操作