Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing SQL from command line?

Status
Not open for further replies.

llevity

Programmer
Nov 7, 2001
5
US
I'm trying to figure out if/how I can execute sql to an informix DB from the command line. I know I can dbaccess dbname filename, but I don't want to have a file...I just want to specify the sql to execute right there from the command line so there's no file to keep up with. Any ideas?
 
llevity:

The informix dbaccess and isql utilities were written as pipes, so if you don't want to use files you can use "here" documents:

dbaccess -e testdb <<EDS
select * from test_table
<<EDS

or

echo &quot;select * from test_table&quot;|dbaccess -e testdb

of you can even take advantage of shell variables:

export DBNAME=testdb

echo &quot;select * from test_table&quot;|dbaccess -e &quot;$DBNAME&quot;

Also, you might put dbaccess in it's own shell script. Call the script x.ss:

dbaccess -e testdb <<EDS
$1
EDs

and call it this way:

x.ss &quot;select * from test_table&quot;

Regards,

Ed
Schaefer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top