Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 964
Sorin Avatar asked Jul 22 '13 07:07

Sorin


2 Answers

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.

like image 56
Benoit Avatar answered Sep 17 '22 21:09

Benoit


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.

like image 31
Jeffrey Kemp Avatar answered Sep 19 '22 21:09

Jeffrey Kemp