Sachin
Sachin

Reputation: 21881

Executing oracle queries in Shell Script

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

Upvotes: 0

Views: 1437

Answers (2)

Venkataramesh Kommoju
Venkataramesh Kommoju

Reputation: 1099

!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.

Upvotes: 1

Thilo
Thilo

Reputation: 262464

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.

Upvotes: 1

Related Questions