在INFORMIX中集成SQL与BASH

阅读更多
在BASH脚本中执行SQL可以通过:

dbaccess [databasename] file.sql

或者:
dbaccess filename.sql

(if the file contains a DATABASE statement at the top.)

To embed SQL in a shell script, you can use a 'here document' approach, which I think is what you're alluding to:
或者在脚本中使用内嵌文档:
#!/bin/ksh

echo "Starting"

dbaccess << EOSQL

    DATABASE foo;

    CREATE TEMP TABLE foobar (foo INT, bar CHAR(10));
    LOAD FROM "foobar.unl" DELIMITER "|"
    INSERT INTO foobar;

    SELECT ...

    UPDATE ...

EOSQL

echo "Finished"


在SQL脚本中使用应用环境变量,如:

SELECT * FROM foobar WHERE bar > $VALUE;


最后在SQL中还可以应用BASH命令:(已经失效了)

dbaccess << EOSQL

    DATABASE foo;

    CREATE TEMP TABLE ...

    `cat $PATH_TO/some_more_sql_in_an_external_file.sql`

    UPDATE ...

EOSQL

你可能感兴趣的:(在INFORMIX中集成SQL与BASH)