쉘 스크립트에서 sqlplus 스크립트를 이용하기

쉘 스크립트안에서 sqlplus 스크립트를 실행하는 방법에 대한 팁이다.
이 팁은 데이터베이스 값을 쉘 변수로 전달하는 방법과 쉘 스크립트를
좀더 다이나믹하게 만들어주는 예이다. 어떤 사람들에게는 기초적인
것일수 있으나 다른 사람들에게 도움이 되기 바란다. 문법은 다음과 같다:

#!/bin/sh
dummyvar=`sqlplus -s username/password  <<end
set pagesize 0 feedback off ver off heading off echo off
select  sysdate from dual;
exit;
end`
echo "system date is " $dummyvar
#end of shell script

이 예제는 오라클에서 시스템의 날짜를 받아오는 것이지만 여러분들이
데이터베이스에서 원하는 정보를 가져와 쉘 변수에 넣도록 select
스크립트를 확장하는 방법에 대한 아이디어를 얻을 수 있다.

@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2578 - January 23, 2007

                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

SHELL SCRIPTING A SQLPLUS SCRIPT

Here is a tip on how to run sqlplus scripts within a shell script.
It is an example of how to pass database values into shell variables
and to make shell scripts more dynamic. This maybe elementary to some
folks but hope it helps others.....Here is the syntax:

#!/bin/sh
dummyvar=`sqlplus -s username/password  <<end
set pagesize 0 feedback off ver off heading off echo off
select  sysdate from dual;
exit;
end`
echo "system date is " $dummyvar
#end of shell script

This will retrieve the system date from Oracle but you get the idea
that you can expand the select script to get whatever you want from
the database and place it in a shell variable where you can make
decisions on it.

반응형
Posted by She쥐포s

블로그 이미지
She쥐포s
Yesterday
Today
Total

달력

 « |  » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

글 보관함