반응형
명령줄에서 sql plus까지 단일 명령어를 발행하려면 어떻게 해야 합니까?
SQL Plus를 사용하면 다음과 같이 명령줄에서 "@" 연산자를 사용하여 스크립트를 실행할 수 있습니다.
c:\>sqlplus username/password@databasename @"c:\my_script.sql"
그러나 동일한 구문을 사용하여 하나의 명령어를 실행할 수 있으며 스크립트 파일 전체를 따로 실행하지 않을 수 없습니다.예:
c:\>sqlplus username/password@databasename @execute some_procedure
저는 이 작업에 관심이 있습니다. 왜냐하면 저는 ".sql" 파일을 생성하지 않고 단순히 명령어를 실행하는 배치 파일을 쓰고 싶기 때문입니다.
SQL*Plus에 연결하여 SQL 쿼리를 실행할 수 있습니다.
@echo select count(*) from table; | sqlplus username/password@database
줘
@echo execute some_procedure | sqlplus username/password@databasename
시도
이런 거 먹어봤어?
sqlplus username/password@database < "EXECUTE some_proc /"
UNIX 에서는, 다음의 조작이 가능한 것 같습니다.
sqlplus username/password@database <<EOF
EXECUTE some_proc;
EXIT;
EOF
하지만 거기에 해당하는 창문이 무엇인지 잘 모르겠습니다.
UNIX(AIX)의 경우:
export ORACLE_HOME=/oracleClient/app/oracle/product/version
export DBUSER=fooUser
export DBPASSWD=fooPW
export DBNAME=fooSchema
echo "select * from someTable;" | $ORACLE_HOME/bin/sqlplus $DBUSER/$DBPASSWD@$DBNAME
sqlplus user/password@sid < sqlfile.sql
이것은, DOS 커맨드 라인에서도 동작합니다.이 경우 파일 sqlfile입니다.sql에는 실행할 SQL이 포함되어 있습니다.
@find /v "@" < %0 | sqlplus -s scott/tiger@orcl & goto :eof
select sysdate from dual;
문제를 해결한 방법은 다음과 같습니다.
<target name="executeSQLScript">
<exec executable="sqlplus" failonerror="true" errorproperty="exit.status">
<arg value="${dbUser}/${dbPass}@<DBHOST>:<DBPORT>/<SID>"/>
<arg value="@${basedir}/db/scripttoexecute.sql"/>
</exec>
</target>
언급URL : https://stackoverflow.com/questions/638705/how-can-i-issue-a-single-command-from-the-command-line-through-sql-plus
반응형
'programing' 카테고리의 다른 글
오류 메시지 "li: 'key' is not prop" (키: 프로펠러가 아닙니다)가 표시됩니다. (0) | 2023.02.27 |
---|---|
'@babel/core' 모듈을 찾을 수 없습니다. (0) | 2023.02.27 |
WooCommerce에서 프로그래밍 방식으로 가변 제품 및 두 가지 새로운 특성 생성 (0) | 2023.02.27 |
material-ui 앱바를 material-ui-next와 함께 사용하여 오른쪽 또는 왼쪽으로 이동하는 올바른 방법은 무엇입니까? (0) | 2023.02.27 |
Controller As 접근 방식을 사용하여 상속된 범위에 액세스 (0) | 2023.02.22 |