python oracle 동작

2337 단어 Oaclepython
cx 다운로드Oacle (자신의 Oacle 버 전, 11g 또는 12c) 에 따라 참고 자 료 를 설치 합 니 다.http://www.oracle.com/technetwork/articles/dsl/prez-python-queries-101587.html http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/oow10/python_db/python_db.htm https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html
코드:
import cx_Oracle
con = cx_Oracle.connect(username, password, host:port/sid)
cursor = con .cursor()

#   
cursor.execute("SELECT * FROM employees ORDER BY emp_no")
rows = cursor.fetchall()
for row in rows:
    print row

data = [
  ('Jane', date(2005, 2, 12)),
  ('Joe', date(2006, 5, 23)),
  ('John', date(2010, 10, 3)),
]
#   many ,     list
stmt = "INSERT INTO employees (first_name, hire_date) VALUES (%s, %s)"
cursor.executemany(stmt, data)

insert_stmt = (
  "INSERT INTO employees (emp_no, first_name, last_name, hire_date) "
  "VALUES (%s, %s, %s, %s)"
)
data = (2, 'Jane', 'Doe', datetime.date(2012, 3, 23))
#   execute ,     touple
cursor.execute(insert_stmt, data)

#     
con.close()

좋은 웹페이지 즐겨찾기