SQL$HELP_OLD72.HLB  —  Execute @, 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
       .
       .
       .
Close Help