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(' Add success ...')

 Add success ...

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',' The programmer ',5000,10000)
cursor.execute(sql)
conn.commit()
print(' Add success ...')

 Add success ...

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(' Table created successfully ...')

 Table created successfully ...

sql = """
insert into jobs_temp
select * from jobs
where jobs.max_salary > 10000
"""
cursor.execute(sql)
conn.commit()
print(' Add success ...')

 Add success ...

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(' The update is successful ...')

 The update is successful ...

sql = "update emp set sal=(select avg(sal) from emp where job='SALESMAN') where sal<2000"
cursor.execute(sql)
conn.commit()
print(' The update is successful ...')

 The update is successful ...

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 success ...')

delete success ...

sql = "truncate table jobs_temp"
cursor.execute(sql)
conn.commit()
print('truncate success ...')

truncate success ...

sql = """insert into jobs_temp values ('DESIGN',' The designer ',3000,5000)"""
cursor.execute(sql)
conn.commit()
print(' Add success ...')

 Add success ...

sql = "truncate table jobs_temp"
cursor.execute(sql)
conn.commit()
print('truncate success ...')
sql = """insert into jobs_temp values ('OFFICE',' Office Clerk ',3000,5000)"""
cursor.execute(sql)
print(' Add success ... The next step is to set the save point ...')
sql = """savepoint sp"""
cursor.execute(sql)
sql = """insert into jobs_temp values ('FINANCE',' financial staff ',3000,5000)"""
cursor.execute(sql)
print(' Add success ... Next, roll back to the savepoint ...')

sql = """rollback to savepoint sp"""
cursor.execute(sql)
conn.commit()
print(' Submit successfully ...')
sql = """select * from jobs_temp"""
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

truncate success ...
Add success ... The next step is to set the save point ...
Add success ... Next, roll back to the savepoint ...
 Submit successfully ...
('OFFICE', ' Office Clerk ', 3000, 5000)

Wu Yuxiong python oracle Operating the database (4) More articles about

  1. Wu Yuxiong python oracle Retrieving data (2)

    import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...

  2. Wu Yuxiong python oracle Usage of subquery (3)

    import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...

  3. Wu Yuxiong python oracle Retrieving data (1)

    import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/ORCL")cursor = conn. ...

  4. Python: Operating the database

    ( One )      Preface This article shows how to connect Oracle.MySQL.sqlserver, And perform sql. Get query results, etc . ( Two )      DB-API      DB-API Clarify a set of required objects and databases ...

  5. MySQL--- The connector (python How to operate database media , be based on python Language )

    MySQL — The connector The concept of connectors They tend to be one kind of Python package , Or something that has been written Python library . These libraries provide us with Python The basic function of connecting to the database server . ​ Since it's a bag , So first we learn to ...

  6. Python Connect to the operation database

    step : 1. Create a connection object to the database : 2. Create cursors : 3. Executing statements through cursors 4. Additions, deletions and changes need to be submitted (commit) data 5. Close the connection Such as : import MySQLdb   # Python adopt MySQL ...

  7. python Operation database

    python In order to operate the database , To use the database in python The corresponding driver library in , In this paper, python operation mysql database 1. First installation pymysql 2. Import library 3. Establishing a connection 4. Create cursors 5. Initiate request 6. ...

  8. python Connect to the operation database ( Two )

    One . Let's continue with the blog of last issue ORM The framework complements , By the way, the paramiko The module also explains to you : 1.ORM frame : It was also said in the first blog that connected to the operation database ,sqlalchemy It's a ORM frame , The conclusion is ...

  9. python Multi thread operation database

    If you use multithreading to operate the database , Easy to cause multi-user operation lock table OperationalError: (2013, 'Lost connection to MySQL server during query') Use ...

Random recommendation

  1. Java Web crawler get page source code

    Original blog post :http://www.cnblogs.com/xudong-bupt/archive/2013/03/20/2971893.html 1. Web crawler is a program that automatically extracts web pages , It's for search engines from the World Wide Web ...

  2. listener About the monitor

    I learned from other people's blogs listener I'd like to share my knowledge with you now 1. Concept : A listener is a common device that implements a specific interface java Program , This program is dedicated to listening to another java Object's method call or property change , When the monitored object happens ...

  3. 【06-18】CentOS Use notes

    Use Chinese input method Sogou input method only supports Ubuntu sudo yum install "@Chinese Support" [ System ]--->[ Preferences ]--->[ typewriting ]--& ...

  4. C# Keep two decimal places after the middle decimal point , Rounding function and how to use it

    Math.Round(45.367,2)     //Returns   45.37 Math.Round(45.365,2)     //Returns   45.36 C# Medium Round() Is not my ...

  5. linux Lower installation uuid library

    1.linux Lower installation UUID library 1.1)ubuntu Lower installation uuid Link library sudo apt-get install uuid-dev 1.2)CentOS yum install libuuid-d ...

  6. 2007 Asia - Nanjing F topic , Dictionary tree

    Topic link :https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=2 ...

  7. Jquery Waterfall flow layout ,jQuery Wookmark Load Example

    Waterfall layout is very suitable for a large number of pictures , A change in the past to cut the size of the picture agreed to typesetting , Every picture can be fully displayed , And it's very well arranged , It's a real eye opener . matters needing attention :img Elemental width and weight Properties need to be written , Otherwise, the positioning will be inaccurate . see j ...

  8. 【XSY2785】 Model

    Title Description Here's a tree for you \(n\) A dot tree , Let you add the least edges , So that there are no cut points in the graph . Request output scheme . \(n\leq 500000\) Answer key Set the weight of the leaf to \(1\), The other points are set to \(0\), Find the center of gravity . With emphasis ...

  9. activiti workflow

    drawing -> Define listening events -> Assign a value to a task -> Deploy (zip Deploy . File deployment )-> Use

  10. bmp Image data to jpg Graphic C Language implementation

    bmp Image format protocol jpg Image format protocol Bmp turn jpg Image code   password :nmaj