zoukankan      html  css  js  c++  java
  • 吴裕雄 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)
  • 相关阅读:
    Unity3D保护资源管理文件的AssetBundle包加密!
    untiy Kinect SDK 的默认BUG 修改方法
    Android 插件扩展系列之 封装与应用
    datagridview 单击单元格获取单元格的内容
    winform 显示动态图片 Gif
    Unity 漫游相机脚本
    Unity3D教程:c#脚本yield的用法
    Unity 脚本实现CoverFlow效果
    删除 treeview Node节点 循环删除子节点 存储过程
    Unity 怪物AI
  • 原文地址:https://www.cnblogs.com/tszr/p/10125079.html
Copyright © 2011-2022 走看看