import cx_Oracle
import traceback
# 조회
def select():
try:
conn=cx_Oracle.connect("test/1234@localhost:1521/xe")
cur=conn.cursor() #커서 생성
sql="select * from employee order by employee_id"
cur.execute(sql)
for row in cur:
for i in range(len(row)):
if i==3:
description=row[3].read() #CLOB필드 읽는 방법
print(row[i], end=" ")
print()
except BaseException as e:
print(traceback.format_exc())
finally:
cur.close()
conn.close()
#select()
# 삽입
def insert(t):
try:
conn=cx_Oracle.connect("test/1234@localhost:1521/xe")
cur=conn.cursor() #커서 생성
sql="insert into employee values(:1,:2,:3,:4,:5)"
cur.execute(sql,t)
except BaseException as e:
print(traceback.format_exc())
finally:
cur.close()
conn.commit()
conn.close()
#insert((1, '개발', '홍길동', '사원', 35))
# 수정
def update(t):
try:
conn=cx_Oracle.connect("test/1234@localhost:1521/xe")
cur=conn.cursor() #커서 생성
sql="update employee set age=:1 where employee_id=:2"
cur.execute(sql,t)
except BaseException as e:
print(traceback.format_exc())
finally:
cur.close()
conn.commit()
conn.close()
#update((1000,11))
# 삭제
def delete(t):
try:
conn=cx_Oracle.connect("test/1234@localhost:1521/xe")
cur=conn.cursor() #커서 생성
sql="delete from employee where employee_id=:1"
cur.execute(sql,t)
except BaseException as e:
print(traceback.format_exc())
finally:
cur.close()
conn.commit()
conn.close()
#delete((10,))
Data/OracleDB
댓글