Re: SQL queries from shell scripts, and capitalisation
Posted in 1997
phil@oyster.co.uk wrote:
>
> I have 2 questions:
>
> (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?
Art mentioned a few methods. Richard's method needs some simplifcation
(is that C-shell syntax? I'm a KSH bigot myself. ;-)
Here's one more, along the lines of Richard's example:
dbaccess mydatabase - <<%%
select * from customer;
update employee set salary = salary * .8 where title != manager;%%
This used the common device called the "hereis" document (the <<string).
if you need to capture the output, you an put the redirection commands
on the command line:
dbaccess mydatabase - <<%% >capture.out
or
dbaccess mydatabase - <<%% | awk -f somescript
> (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
> case with the 1st character of every word capitalised, and
> the other characters in lower case. Is it possible to do
> this in SQL? I have heard of user-defined functions, but
> the manual (specifically page 1-683 of the "Informix Guide
> to SQL version 7.2 volume 2") doesn't mention them in the
> syntax for functions which seems to imply that they are not
> available for the OnLine database. Is this right?
>
> Assuming I am able to do the case conversion using either a
> shell script (I'd probably use Perl) or within the database
> itself, which is likely to be faster? In the FAQ I have seen
> some example code which basically compares each character
> with each one of 'a' to 'z' one character at a time, and
> it seems to me that this will not be very fast.
Capture the data and run it through an awk or perl script.
--
-- Jake (In pursuit of undomesticated aquatic avians)
+----------------------------------------------------------+
|Aside from that, how did you enjoy the play, Mrs. Lincoln?|
+----------------------------------------------------------+