yeonghoon.kim

  • 게시판
  • 갤러리
  • aws

Python cx_Oracle 모듈 샘플코드

김영훈 2023.03.03 21:08 조회 수 : 369

import cx_Oracle

 

# 1. 오라클 클라이언트 HOME 지정

cx_Oracle.init_oracle_client(lib_dir="C:\instantclient_19_18")

 

 

# 2. 접속 정보 설정

user_name = "ID"

user_password = "PASSWORD"

service_name = "127.0.0.1:1521/ORCL"

 

 

# 3. db 접속

db_connection = cx_Oracle.connect(user_name, user_password, service_name)

cursor = db_connection.cursor()

 

 

# 4. 쿼리 String으로 변수 지정

sql = """

    SELECT *

    FROM BR_ADMIN_TEST_IP

"""

 

# 5. 쿼리 실행

result = cursor.execute(sql)


 

# 6. fetchall(모든 줄), fetchone(하나만)

out_data_one = result.fetchone()

out_data_all = result.fetchall()


 

# 7. 1줄만 추출할 경우

print("[1줄 추출]")

print(out_data_one)

print("")


 

# 8. 결과값 모두 추출할 경우

print("[여러 줄 추출]")

for row in out_data_all:

    print(row)


 

# 9. db 접속 종료

db_connection.close()


  • 추천 0

  • 비추천 0
이 게시물을
목록

댓글 0

사진 및 파일 첨부

여기에 파일을 끌어 놓거나 왼쪽의 버튼을 클릭하세요.

파일 용량 제한 : 0MB (허용 확장자 : *.*)

업로드 중... (0%)

0개 첨부 됨 ( / )
 
번호 제목 글쓴이 날짜 조회 수
공지 2025 일본 여행 계획 김영훈 2024.10.10 1308
공지 현금, 저축, 투자, 지출, 예산, 보험 내역(2024-05-30) 김영훈 2024.03.10 1030
226 데이터베이스 2주차 - 실습 김영훈 2023.03.08 350
225 시스템프로그래밍 2주차 - 사용명령 김영훈 2023.03.08 301
» Python cx_Oracle 모듈 샘플코드 김영훈 2023.03.03 369
223 아이맥 화면 동영상 캡처 - 커맨드 + 쉬프트 + 5 김영훈 2023.02.28 270
222 paramiko 일괄 명령 테스트 김영훈 2023.01.05 360
221 파이썬 디스크 용량 체크 김영훈 2023.01.04 483
220 Uptime Kuma용 push(패시브) 체크용 파일.py [1] 김영훈 2022.12.21 332
219 python - re 라이브러리 김영훈 2022.12.19 359
218 python - requests 라이브러리 김영훈 2022.12.19 281
217 python - socket 라이브러리 김영훈 2022.12.19 372
216 python - random 라이브러리 김영훈 2022.12.19 328
215 CentOS7 아나콘다 환경에 주피터 노트북 설치 김영훈 2022.12.03 676
214 CentOS7 - minikube 설치 김영훈 2022.12.02 419
213 growpart - no tools available to resize disk with 'gpt' 김영훈 2022.12.01 294
212 mac homebrew 설치 김영훈 2022.11.30 246
211 centos7 gitlab 설치 김영훈 2022.11.28 348
210 Your account is pending approval from your GitLab administrator and hence blocked. Please contact your GitLab administrator if you think this is an error. 김영훈 2022.11.28 503
209 mac에서 centos6 ssh 접속 시 오류 - no matching host key type found. Their offer: ssh-rsa,ssh-dss 김영훈 2022.11.27 420
208 Centos Console 화면 보호기 setterm 김영훈 2022.11.26 243
207 CentOS8-Stream packstack 설치 [5] 김영훈 2022.11.24 425
쓰기 태그
 첫 페이지 1 2 3 4 5 6 7 8 9 10 끝 페이지