programing

sqlplus를 사용하여 Oracle DB에 연결

instargram 2023. 10. 14. 09:32
반응형

sqlplus를 사용하여 Oracle DB에 연결

저는 유닉스 환경에서 아래 명령어를 사용하여 오라클 데이터베이스에 연결하고 있습니다.

sqlplus test/test@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname.com )(PORT=1521)))(CONNECT_DATA=(SID=mysid))'

하지만 저는 오류가 적어지고 있습니다.

Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus statements.

Usage 1: sqlplus -H | -V

    -H             Displays the SQL*Plus version and the
                   usage help.
    -V             Displays the SQL*Plus version.

Usage 2: sqlplus [ [<option>] [{logon | /nolog}] [<start>] ]

  <option> is: [-C <version>] [-L] [-M "<options>"] [-R <level>] [-S]

제가 명령어를 잘못 사용하고 있는 부분을 도와주시기 바랍니다.

시도해 보십시오.sqlplus USER/PW@//hostname:1521/SID

sqlplus 사용자 이름/password@

예:

sqlplus hr/hr@orcl

유닉스 사용자로부터 Oracle Database를 연결하는 다른 방법은 다음과 같습니다.

[oracle@OLE1 ~]$ sqlplus scott/tiger

[oracle@OLE1 ~]$ sqlplus scott/tiger@orcl

[oracle@OLE1 ~]$ sqlplus scott/tiger@192.168.244.128:1521/orcl

[oracle@OLE1 ~]$ sqlplus scott/tiger@//192.168.244.128:1521/orcl

[oracle@OLE1 ~]$ sqlplus "scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ole1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"

https://stackoverflow.com/a/45064809/6332029 링크에서 설명을 참조하시기 바랍니다.

감사합니다!

쉬운 방법(XE 사용):

1). tns 이름을 구성합니다.ora

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = HOST.DOMAIN.COM)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

호스트를 교체할 수 있습니다.도메인.IP 주소를 가진 COM, TCP 포트는 기본적으로 1521(체크 잇)이며 이 구성의 이름이 XE임을 확인합니다.

2). sqlplus라는 이름의 앱을 사용하면 다음과 같습니다.

sqlplus SYSTEM@XE

시스템은 공인된 사용자로 교체되어야 하며, 프롬프트가 나타나면 비밀번호를 입력해야 합니다.

3). 방화벽에서 일부 차단된 TCP 포트의 가능성을 확인하고 나타나면 수정합니다.

오라클 데이터베이스에 연결하려는 경우

  1. open sql 프롬프트
  2. XE-conn의 경우 sysdba로 연결 / IE의 경우 sysdba로 연결 sysdba로 연결
  3. 그런 다음 아래 명령 시작을 통해 데이터베이스를 시작합니다.

시작하면 Oracle 데이터베이스에 액세스할 수 있습니다.다른 사용자를 연결하려면 conn 사용자 이름/비밀번호(예: conn scott/ tiger)를 작성할 수 있습니다. 그러면 connected..........

tnsping xe --if you have installed express edition
tnsping orcl --or if you have installed enterprise or standard edition then try to run
--if you get a response with your description then you will write the below command
sqlplus  --this will prompt for user
hr --user that you have created or use system
password --inputted at the time of user creation for hr, or put the password given at the time of setup for system user
hope this will connect if db run at your localhost.
--if db host in a remote host then you must use tns name for our example orcl or xe
try this to connect remote
hr/pass...@orcl or hr/pass...@xe --based on what edition you have installed

David Aldridge가 설명했듯이 괄호는 sqlplus 명령어 바로 뒤에 시작해야 하므로 다음과 같습니다.

sqlplus 'test/test@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname.com )(PORT=1521)))(CONNECT_DATA=(SID=mysid))'

이런 식일 겁니다.

sqlplus -s /nolog  <<-!
connect ${ORACLE_UID}/${ORACLE_PWD}@${ORACLE_DB};
whenever sqlerror exit sql.sqlcode;
set pagesize 0;
set linesize 150;
spool <query_output.dat> APPEND
@$<input_query.dat>
spool off;
exit;
!

여기서

ORACLE_UID=<user name>
ORACLE_PWD=<password>
ORACLE_DB=//<host>:<port>/<DB name>

언급URL : https://stackoverflow.com/questions/15661076/connect-to-oracle-db-using-sqlplus

반응형