[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to do multiple commands as command line arguments for GNU sql
From: |
Ole Tange |
Subject: |
How to do multiple commands as command line arguments for GNU sql |
Date: |
Tue, 14 Sep 2010 23:39:32 +0200 |
If you want to use GNU sql for running multiple commands on Oracle you
will have to do something like:
sql oracle://hr:hr@/xe "SELECT 1 FROM DUAL;
SELECT 2 FROM DUAL;"
I do not like the part that you have to put a newline on the command
line. You can of course do:
(echo "SELECT 1 FROM DUAL;"; echo "SELECT 2 FROM DUAL;") | sql
oracle://hr:hr@/xe
but I really would like to make it possible to give the SQL queries as
arguments. So I am thinking about this:
sql oracle://hr:hr@/xe "SELECT 1 FROM DUAL;" "SELECT 2 FROM DUAL;"
sql oracle://hr:hr@/xe "WHENEVER SQLERROR EXIT FAILURE" "SELECT 1
FROM DUAL;" "SELECT 2 FROM DUAL;"
i.e. each argument will get a newline added before being passed along
to sqlplus. I have implemented this in the current git version.
An alternative:
sql oracle://hr:hr@/xe "SELECT 1 FROM DUAL;\nSELECT 2 FROM DUAL;"
sql oracle://hr:hr@/xe "WHENEVER SQLERROR EXIT FAILURE\nSELECT 1
FROM DUAL;\nSELECT 2 FROM DUAL;"
Where '\n' will be substituted with a newline. Personally I find the
first version easier to read.
Another alternative:
sql oracle://hr:hr@/xe "SELECT 1 FROM DUAL;%0aSELECT 2 FROM DUAL;"
sql oracle://hr:hr@/xe "WHENEVER SQLERROR EXIT FAILURE%0aSELECT 1
FROM DUAL;%0aSELECT 2 FROM DUAL;"
Where '\n' will be substituted with a newline. Personally I find the
first version easier to read. Also % is being used in LIKE.
Which one do you like better? Do you have other ideas?
/Ole
- How to do multiple commands as command line arguments for GNU sql,
Ole Tange <=