Run DB-Access in interactive mode without menus

If you do not want to use the menus and do not have a prepared SQL file, use your keyboard or standard input device to enter SQL statements from the command line.

When you start DB-Access without a menu argument and with a hyphen as the final argument, DB-Access processes commands from the standard input device (on UNIX) or the keyboard (on Windows). DB-Access reads what you type until you indicate that the input is completed. Then DB-Access processes your input and writes the results to the standard output device (on UNIX), or the command window (on Windows).

DB-Access reads and runs SQL statements from the terminal keyboard interactively. While DB-Access runs interactively, the greater than (>) prompt marks the line where you type your next SQL statement.

When you type a semicolon (;) to end a single SQL statement, DB-Access processes that statement. When you press CTRL-D to end the interactive session, DB-Access stops running. The following example shows user input and results in an interactive session:
dbaccess - -
>database stores_demo;

Database selected.

>select count(*) from systables;

(count(*))

     21

1 row(s) retrieved.

>^D

dbaccess - -
>database stores_demo;

Database selected.

>select count(*) from systables;

(count(*))

     21

1 row(s) retrieved.

>^D

Batch command input (UNIX)

You can use an inline shell script to supply one or more SQL statements. For example, you can use the UNIX C, Bourne, or Korn shell with inline standard input files:
dbaccess mystores- <<EOT!
select avg(customer_num) from customer
where fname matches '[A-G]*';
EOT!
You can use a pipe to supply SQL statements, as in this UNIX example:
echo 'select count(*) from systables' | dbaccess mystores
DB-Access interprets any line that begins with an exclamation mark (!) as a shell command. You can mix shell escape lines with SQL statements and put them in SQL statements, as follows:
dbaccess mystores -
>select
!echo hello
>hello
count(*) from systables;
>
(count(*))

     21

1 row(s) retrieved.
>

View and rerun DB-Access commands

You can view and rerun DB-Access commands that you ran from the command line during the current session.

To view the previous commands, run the dbaccess -history command. In the following example, the command history shows three previous commands:

dbaccess -history - -
1> create database sales_demo;

Database created.

2> create table customer (
2>        customer_code integer,
2>        customer_name char(31),
2>        company_name char(20));

Table created.

3> insert into customer values (102, "Carole Sadler", "Sports Spot");

1 row(s) inserted.

4> history;

1   create database sales_demo
2   create table customer (
           customer_code integer,
           customer_name char(31),
           company_name char(20))
3   insert into customer values (102, "Carole Sadler", "Sports Spot")

You can rerun the third command by running the run 3 command:


4> run 3;

1 row(s) inserted.