在BASH脚本中执行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:
或者在脚本中使用内嵌文档:
在SQL脚本中使用应用环境变量,如:
[color=red]最后在SQL中还可以应用BASH命令:(已经失效了)[/color]
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;
[color=red]最后在SQL中还可以应用BASH命令:(已经失效了)[/color]
dbaccess << EOSQL
DATABASE foo;
CREATE TEMP TABLE ...
`cat $PATH_TO/some_more_sql_in_an_external_file.sql`
UPDATE ...
EOSQL