next up previous contents
Next: PL/SQL Up: Oracle Programming Previous: Oracle Programming   Contents


SQL can be "scripted" in the purest sense of the word by simply dumping all your SQL statements into a flat file, naming it something.sql and then running it. There is no logic, just SQL as you'd enter it in SQL*Plus. Comments can be added by prefixing them with "-".

You can execute your SQL in one of two ways, via the SQL*Plus command line, by proceeding the filename with an and leaving off the implied .sql extension, or via SQL*Plus's non-interactive mode, ala: sqlplus user/passwd script, leaving off the .sql just as with the interactive form.

Here's an example:

oracle@nexus6 PLSQL$ cat sample1.sql 
-- Sample of a simple sql script
-- Non-PL/SQL
         i int,
         s char(10)

INSERT INTO test VALUES(1, 'foobar');
INSERT INTO test VALUES(2, 'fooba');
INSERT INTO test VALUES(3, 'foob');
INSERT INTO test VALUES(4, 'foo');
INSERT INTO test VALUES(5, 'foobar');
INSERT INTO test VALUES(6, 'fobar');
INSERT INTO test VALUES(7, 'fbar');
INSERT INTO test VALUES(8, 'bar');
oracle@nexus6 PLSQL$ sqlplus ben/passwd
SQL> @sample1      
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> select * from test where i = 1;

         I S
---------- ----------
         1 foobar
SQL> drop table test;
Table dropped.