[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 求助排错批处理for语句输出多条sql命令语句报错“此时不应有……”

本帖最后由 pcl_test 于 2016-8-16 20:08 编辑
  1. @echo off
  2. rem =======================================================================
  3. rem = 本批处理实现目录数据同步到中心                      ---20160816   =
  4. rem =======================================================================
  5. set DumpFolder=d:\dmp
  6. set LogFolder=d:\log
  7. set FileDate=%Date:~0,4%%Date:~5,2%%Date:~8,2%
  8. set UserName=datacenter
  9. set Password=datacenter
  10. set NetServer=orcl
  11. for /f "tokens=1 delims=_" %%i in ('dir /a-d /b *.dmp') do (
  12. echo insert into rc_catalog_basic_bak select * from rc_catalog_basic where ORGANIZATION_ID = '%%i';>%DumpFolder%\pre.sql
  13. echo insert into rc_resource_info_bak select * from rc_resource_info t where (t.catalog_resource_id,t.version) in (select catalog_resource_id,version from rc_catalog_basic where ORGANIZATION_ID = '%%i');>>%DumpFolder%\pre.sql
  14. echo insert into rc_dynamic_authority_bak select * from rc_dynamic_authority t where (t.catalog_resource_id,t.version) in (select catalog_resource_id,version from rc_catalog_basic where ORGANIZATION_ID = '%%i');>>%DumpFolder%\pre.sql
  15. echo commit;>>%DumpFolder%\pre.sql
  16. echo delete from rc_catalog_basic where ORGANIZATION_ID = '%%i';>>%DumpFolder%\pre.sql
  17. echo delete from rc_resource_info t where (t.catalog_resource_id,t.version) in (select catalog_resource_id,version from rc_catalog_basic where ORGANIZATION_ID = '%%i');>>%DumpFolder%\pre.sql
  18. echo delete from rc_dynamic_authority t where (t.catalog_resource_id,t.version) in (select catalog_resource_id,version from rc_catalog_basic where ORGANIZATION_ID = '%%i');>>%DumpFolder%\pre.sql
  19. echo commit;>>%DumpFolder%\pre.sql
  20. echo 前置机%%i数据环境初始化开始。。。
  21. start /b /wait sqlplus %UserName%/%Password%@%NetServer% @%DumpFolder%\pre.sql >%LogFolder%\%%i_%Date:~0,4%%Date:~5,2%%Date:~8,2%.log
  22. echo 前置机%%i数据环境初始化完毕!
  23. )
  24. pause
复制代码
下面这个就没事,奇怪死了==
  1. @echo off
  2. echo insert into rc_catalog_basic_bak select * from rc_catalog_basic where ORGANIZATION_ID = '%%i';>pre.sql
  3. echo insert into rc_resource_info_bak select * from rc_resource_info t where (t.catalog_resource_id,t.version) in (select catalog_resource_id,version from rc_catalog_basic where ORGANIZATION_ID = '%%i');>>pre.sql
  4. pause
复制代码
谢谢大神的帮助~~~~~

本帖最后由 dreamer 于 2016-8-16 19:36 编辑

我覺得是sql 語法的() 問題,將() 換成^( ^)試試



補充:
已測試,替換後可執行

TOP

13-18行的  )  改为  ^)
初学BAT,非专业。代码不适当之处还望前辈们多多指点。在此表示感谢!

TOP

cmd语法检测比较粗略,对于嵌套的括弧不能很好的识别匹配
语法上do (与就近的where (t.catalog_resource_id,t.version)识别为成对括弧,提前闭合语句了

TOP

还是sql...
非常批处理3群:56794763
有偿写程序.
批处理, lua, c, c++, vba, php, css

TOP

返回列表