0

这是我的第一个批处理文件,我一直无法找到答案(或我可以破译的线索)。编程新手,尝试在单个批处理文件中运行多个 .sql 语句。这是我能做到的。问题是,苍蝇一次只处理一只股票,底部的 2 个 COUNTS 文件会重复自己 - 所以我需要在用户更改第一个 .sql 文件中的股票代码并让它们循环运行之后运行它们直到输入最后一个库存——然后在最后运行 COUNTS 个文件。

@echo off
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good  scripts\load_csv_data_MySQL.sql"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DAILY.sql"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_MONTHLY.sql"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DEFAULT_updates.sql"

:this is where I need to have the file either loop back through the above scripts with 
:a different stock (with files above updated by the batch user who has access to the  .sql files) or when
:all stocks have been entered, to continue to the 2 .sql scripts below

mysql -h  -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_daily.sql"
mysql -h  -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_monthly.sql"
exit

非常感谢任何帮助(请记住我完全缺乏批处理文件的经验)!PS这是一项个人作业,不适用于任何类型的学校,我现在只使用网络自学(和Murach的MySQL书)......

谢谢!

4

2 回答 2

0

如果mysql命令不会改变,这将正常工作:

代码 :

@echo off
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
:start
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good  scripts\load_csv_data_MySQL.sql"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DAILY.sql"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_MONTHLY.sql"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DEFAULT_updates.sql"
choice /m "Restart Operation ?"
if %errorlevel% equ 1 goto :start
mysql -h  -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_daily.sql"
mysql -h  -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_monthly.sql"
exit

如果没有,我无能为力,因为我自己不熟悉

希望这有帮助。

于 2013-07-22T02:01:51.700 回答
0
@echo off
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
:again
set "stock="
set /p stock="enter stock symbol "
if not defined stock goto final
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good  scripts\load_csv_data_MySQL.sql"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DAILY.sql"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_MONTHLY.sql"
mysql -h  -u -p -Dstock_market < "C:\mysql assignment\1\good scripts\derived_DEFAULT_updates.sql"

goto again

:final

mysql -h  -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_daily.sql"
mysql -h  -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_monthly.sql"
exit

这应该让你开始 - 将接受股票代码;按下Enter应该运行最后两个并退出。

我收集输入的股票必须用于修改循环中的 4 个脚本。这是一个完全不同的任务。并非不可能,但确实增加了复杂性。你应该能够让你的.sql脚本接受一个参数(我不是.sql脚本专家,所以我不知道具体如何)或者只是.sql从模板重建,替换一个关键字符串......

于 2013-07-22T02:16:05.280 回答