Sorin
Sorin

Reputation: 910

What does the "@" do in SQL*Plus

I found this line in a sql code:

@../../sql_scripts/create_tables.sql

What does it do? I know that @@file.sql means that file.sql is run and @ could be used when we want to supply parameter values later, but here I have @ followed by a filename. I know that there is a similar question but it covers only @ in queries.

Upvotes: 5

Views: 908

Answers (2)

Jeffrey Kemp
Jeffrey Kemp

Reputation: 60292

The @ allows you to import another script into the sql script you're running in SQL*Plus.

For example, this executes the contents of otherscript.sql at the specified point:

PROMPT about to run other script

@otherscript.sql

PROMPT finished running other script

Another example, this inserts the contents of another file into the middle of a statement to be executed in SQL*Plus:

SELECT * FROM mytable WHERE
@predicates_for_mytable.sql
AND bla = 1;

The only condition is that @ must appear at the 1st character on the line.

Upvotes: 1

Benoit
Benoit

Reputation: 79235

Here the @ is not part of the SQL language. It is likely a command for the SQL interpreter which is probably Oracle SQL*Plus.

SQL*Plus has many single-character commands like @ or / (which executes buffered SQL), ; which can be puzzling when you encounter them in an .sql file.

@ is documented here in Oracle 9i documentation. There you will see the differences with @@.

documentation for Oracle 11g Release 2, click Next section for @@ reference.

Upvotes: 6

Related Questions