2016-08-26 8 views
1

SQL * Plus 명령을 실행하는 일괄 처리 스크립트가 있으며 출력을 CSV 파일로 스풀링하고 있습니다. 모든 출력에는 하나의 열 "개수"만 있습니다. 결과에 텍스트를 추가하는 방법이 있습니까?sqlplus 및 스풀 옵션

"The_current_valueOf Query1" "Count1" 
"The_current_valueOf Query2" "Count2" 

어떤 도움이나 조언을 부탁드립니다.

set colsep , 
set pagesize 0 
set trimspool on 
set headsep off 
set Newpage none 

spool D:\TRHMIBS\TRH\TRHStats.csv 
select count(*) from host.ufm where insert_time between trunc(sysdate) and sysdate 
/
spool D:\TRHMIBS\TRH\TRHStats.csv APPEND 

select count(*) from host.amendment where insert_time between trunc(sysdate) and sysdate and msg_source = 'AUDIT' 
/
spool D:\TRHMIBS\TRH\TRHStats.csv APPEND 
select count(*) from host.ufm_amendment where insert_time between trunc(sysdate) and sysdate and msg_source = 'DAS' and ext_token is null 
/
spool off; 

exit; 

답변

2

메시지를 하드 코딩 된 리터럴로 선택할 수 있습니다. 예 :

1

이것은 스풀링과 관련이 없습니다. 두 번째 및 세 번째 spool 명령은 중복되어 있습니다. 해제 할 때까지 열려있는 파일에 모든 내용이 스풀됩니다. 하지만 그것은 측면 문제입니다.

문자열 리터럴이 될 수있는 열 표현식을 사용하여 출력에 다른 열을 추가 할 수 있습니다. 따라서 첫 번째 쿼리를

select 'The_current_valueOf Query1', count(*) 
from host.ufm 
where insert_time between trunc(sysdate) and sysdate 

으로 변경 한 다음 다른 두 가지 쿼리에 대해 동일한 작업을 수행 할 수 있습니다. 당신은 CSV로 그것을 원하기 때문에

당신은 혼자가 colsep를 떠나 당신이 연결로 할 수있는 그 안에 포함 된 쉼표, 단일 열 수 :

select 'The_current_valueOf Query1,' || count(*) 
from host.ufm 
where insert_time between trunc(sysdate) and sysdate 

을 오히려 별도의 세 가지 쿼리 당신 을 실행하는 것보다를 그들은 노조 함께 할 수 있었다; 처리를 저장하지 않지만 출력이 모두 함께 제공됨을 의미합니다.

select 'The_current_valueOf Query1,' || count(*) 
from host.ufm 
where insert_time between trunc(sysdate) and sysdate 
union all 
select 'The_current_valueOf Query1,' || count(*) 
from host.amendment 
where insert_time between trunc(sysdate) and sysdate 
union all 
...