views:

229

answers:

2

Please tell me how can i excute an oralce query inside a shell script.I am writing a shell script where I need to execute the oracle queries and scripts inside the shell script.

What is the purpose of these lines

sql_file=sachin.sql
cat <<!SQL > $sql_file
        select $1 from dual;
        exit;
!SQL

I think they are creating a new file, but what exactly is !SQL

+1  A: 

It is the multi-line string terminator (a here-doc). There is no special meaning to the letters used, you could just as well have written !ORACLE, it just denotes that the content of the multi-line string are SQL commands.

What your script does is create a text file called sachin.sql with the contents specified between the two !SQL tokens.

PS: Not sure what shell this is for, my bash does not like the exclamation mark, thinks it is an event.

Thilo
I am using ksh shell.A quick question here, If we just want to create a temporary sql file, then cant we do it by just creatig a file using touch and append the queries later on using cat
Sachin Chourasiya
+1  A: 

!SQL is just a token to notify the end of sql statements (here-doc) we can use any token like EOF, ENDSQL anything.

but the pre-requisite is the second token !SQL should start on the first column of the line.

Venkataramesh Kommoju