RE: SQL queries from shell scripts, and capitalisation
Posted in 1997
Phil wrote:
> (1) How do I run an SQL query from the Unix shell? In the
> FAQ it talks about running isql, but this doesn't seem to
> be on my system. Is isql part of OnLine or does it only
> come with the other Informix database?
> (2) I have a table which includes a row of strings which
> are in all upper case. I want to output the result in mixed ...
(Proper Case or Title Case)
[ snip ]
ISQL is a separate product which adds report and form functionality to the =
more basic DBACCESS. To use SQL from the shell, it is not strictly =
necessary. You can use any of the following:
dbaccess -e stores << EOSQL
SELECT * FROM customer;
EOSQL
- or -
echo "SELECT * FROM customer" | dbaccess stores
Basically, it's just redirection (or stdin) to the dbaccess command. You =
can also embed this directly into a perl (if that's what you want to do to =
create your proper_case function), eg:
$sql =3D<<EOSQL ;
SELECT * FROM customer;EOSQL
open(STDIN, "echo \\"$sql\\" | dbaccess stores 2>/dev/null |")
|| die "SQL failed $!\\n";
while(<>){
#unpack or break up your strings here - be careful of whether the output =
is
#horizontal or vertical
$name =3D &proper($name);
}
Get the idea?
User defined functions (SPL) is covered in the SQL Tutorial, but I think =
you would find writing this function in SPL extremely cumbersome.
regards
RET
+--------------------------------------------------------------------------=
----+
| Richard Thomas (DBA) richard_thomas@yes.optus.com.au +61 2 9342 =
7188 |
+--------------------------------------------------------------------------=
----+