LoginSignup
0
1

More than 3 years have passed since last update.

[Python] Oracle DBに接続する

Posted at

import datetime

import numpy as np
import pandas as pd
import cx_Oracle as orcl


TARGET_HOST = "xx.xx.x.x"
PORT = "1521"
SERVICE_NAME = "***"
USERNAME = "***"
PASSWORD = "***"

## 接続識別子の作成
tns = orcl.makedsn(TARGET_HOST, PORT, service_name=SERVICE_NAME)

## DBへの接続
ora_con = orcl.connect(USERNAME, PASSWORD, tns)

SQL="""
select *
from table
"""

# データを取得してDataFrameへ変換
df = pd.read_sql(SQL, con=ora_con)
df.head()

## DBセッションの終了
ora_con.close()

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1