In SQL, the at sign (@) means execute. When you type @ and the name of an indirect command file, SQL executes the statements in that file as if you typed them one-at-a-time at the SQL prompt (SQL>). The command file must be a text file that contains SQL statements. The default file extension for an indirect command file is .SQL. You can use the SET VERIFY statement to display the commands in the file as they execute. SQL recognizes a special SQL command file called SQLINI.SQL, which contains SQL statements to be issued before SQL displays the SQL prompt (SQL>). If this file exists, SQL executes the commands in the file first, before displaying the prompt and accepting your input. If you define the logical name to point to a general initialization file, SQL uses this file. Otherwise, it looks for SQLINI.SQL in the current default directory.
1 – Environment
You can issue the execute (@) statement only in interactive SQL.
2 – Format
@<file-spec>
3 – Arguments
3.1 – file-spec
Specifies the name of an indirect command file. You can use either a full file specification, a file name, or a logical name on OpenVMS. If you use a file name, SQL looks in the current default directory for a file by that name. The file must contain valid SQL statements.
4 – Examples
Example 1: Storing interactive SQL statements in a startup file You can use an indirect command file to specify characteristics of your SQL terminal session. This example assumes that SQLINI is defined as a logical name that points to the file setup.sql. The file contains the following SQL statements: SET VERIFY; SET EDIT KEEP 5; -- This line will be displayed on the terminal SQL executes the file when you invoke interactive SQL. $ SQL$ SQL> SET EDIT KEEP 5; -- This line will be displayed on the terminal SQL> When it executes, setup.sql turns on the indirect command file display and limits the number of statements saved by SQL for editing to five. Example 2: Executing frequently used queries The file EMPADDR.SQL contains the following SQL statements: -- This command file generates information for a mailing list. -- ATTACH 'FILENAME personnel'; SET OUTPUT MAILLIST.DOC SELECT FIRST_NAME, MIDDLE_INITIAL, LAST_NAME, ADDRESS_DATA_1, ADDRESS_DATA_2, CITY, STATE, POSTAL_CODE FROM EMPLOYEES; -- -- Execute the file by using the following command: -- @EMPADDR Example 3: Using a logical name to run a command file If you define COUNT to be a logical name, you can use the command @COUNT to execute the statements in the file, even if the file is located in a directory other than the default directory. The file COUNT.SQL contains the following SQL statements: -- This command file counts the rows in -- each table of the personnel database. -- SET NOVERIFY; SELECT 'Count of Employees -------> ', COUNT (*) FROM EMPLOYEES; SELECT 'Count of Jobs ------------> ', COUNT (*) FROM JOBS; SELECT 'Count of Degrees ---------> ', COUNT (*) FROM DEGREES; SELECT 'Count of Salary_History --> ', COUNT (*) FROM SALARY_HISTORY; SELECT 'Count of Job_History -----> ', COUNT (*) FROM JOB_HISTORY; SELECT 'Count of Work_Status -----> ', COUNT (*) FROM WORK_STATUS; SELECT 'Count of Departments -----> ', COUNT (*) FROM DEPARTMENTS; SELECT 'Count of Colleges --------> ', COUNT (*) FROM COLLEGES; The following example shows how to execute the file and the output: $ SQL SQL> @COUNT; Count of Employees -------> 100 1 row selected Count of Jobs ------------> 15 1 row selected Count of Degrees ---------> 166 1 row selected . . .