Board logo

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

作者: paopaomm    时间: 2016-8-16 19:18     标题: 求助排错批处理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:33

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

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



補充:
已測試,替換後可執行
作者: xxpinqz    时间: 2016-8-16 19:42

13-18行的  )  改为  ^)
作者: pcl_test    时间: 2016-8-16 20:19

cmd语法检测比较粗略,对于嵌套的括弧不能很好的识别匹配
语法上do (与就近的where (t.catalog_resource_id,t.version)识别为成对括弧,提前闭合语句了
作者: jains521    时间: 2016-8-17 18:44

还是sql...




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2