0

I have a SQL filequery.sql running thorugh a unix shell script and it directs an ouput to another SQL file called as result.sql

First file will give the sample output of below which will be written in the result.sql,

drop * from table1;
drop * from table 2;
drop * from table 3;  etc.. 

I need to execute both query.sql and result.sql in a single shell script and this should create a output file called as output.txt. How can I achieve this?

1 Answer 1

1

Something on this idea should work:

sqlplus -s username/password@servername << EOF
@query.sql
spool output.txt
@result.sql
spool off
EOF
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, Thanks for your comments. Actually the result.sql is the output of the query.sql. here i need to execute the first query file (query.sql) and to get the output in the second file(result.sql). And this two files needs to be executed in the same shell script file and output of the result.sql to be written in the output.txt file.
Hi @Ed, My first file query.sql contains the below CONNECT username/password@SID whenever SQLERROR EXIT 1; set linesize 32767 set heading off set termout off set trimout on set pagesize 50000 set trimspool on set feedback OFF SET SQLBLANKLINES ON --set markup html ON echo OFF spool /tmp/chan/result.sql SELECT CONCAT(CONCAT('select count(*) from ',TABLE_NAME),';') AS QUERYSET FROM USER_TABLES WHERE REGEXP_LIKE (LOWER(TABLE_NAME),'^bpjd_job_dependency_(pre|pst)_') order by TABLE_NAME desc; spool off; exit;
Your query.sql seems solid. I've moved the spool output.txt in my answer above so it comes just before the @result.sql; therefore it will only capture output from when you run result.sql. You'll also want to specify your folder when you run it: @/tmp/chan/result.sql.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.