본문 바로가기

카테고리 없음

ORACLE INSTANT CLIENT , PYTHON 을 이용한 접속 테스트 및 SELECT

-----------------------------------------------------------------

-- ORACLE INSTANT CLIENT

-----------------------------------------------------------------


# rpm -qa | grep inst

oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64

oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64

oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64



-------------------------------------------------------------------

-- vi ~/.bash_profile

-------------------------------------------------------------------


export TNS_ADMIN=/usr/lib/oracle/12.1/client64/network/admin

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/12.1/client64/lib

export PATH=$PATH:$HOME/bin:/usr/lib/oracle/12.1/client64/bin





---------------------------------------------------------------

-- vi tnsnames.ora

---------------------------------------------------------------


# cd /usr/lib/oracle/12.1/client64

# mkdir -p network/admin

# cd network/admin



TEST =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = IP주소)(PORT = 1521))

    (ADDRESS = (PROTOCOL = TCP)(HOST = IP주소)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = 서비스이름)

    )

  )


  

----------------------------------------------------  

-- CHECK CONNECTION TO ORACLE USING TNS NAME

----------------------------------------------------  


sqlplus system/(PASSWORD)@(TNS NAME)




-----------------------------------------------------------

-- CHECK CONNECTION TO ORACLE USING PYTHON SCRIPT

-----------------------------------------------------------



import cx_Oracle

conn = cx_Oracle.connect(user="system",password="(PASSWORD)",dsn="(TNS NAME)");

cur = conn.cursor()

cur.execute('select host_name from v$instance')

res = cur.fetchmany(numRows=1)

print res

cur.close()

conn.close()

exit()