Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

Call MySQL stored procedure with parameter from batch file

Do you know how to call a MySQL stored procedure from batch file?

Thank you ;)

I change my mind and I decided to create batch calling sql file :

My batch

@ECHO OFF
 cls


setlocal enableDelayedExpansion

SET MYSQL_EXE="C:Program FilesMySQLMySQL Server 5.6inmysql.exe"
SET DB_USER=****
SET DB_PWD=***
SET DB=***

set DD=%DATE:~0,2%
set MM=%DATE:~3,2%
set YY=%DATE:~8,2%
set YYYY=%DATE:~6,4%
set HH=%TIME:~0,2%
set MN=%TIME:~3,2%

SET "CURRDAT=%YYYY%-%MM%-%DD% %HH%:%MN%:00"



  FOR /F  %%f in ('DIR "K:CRNTRAVAILPROGRAMMATIONPrev ConsocsvPCE_PRECO20140522*.*" /B') DO (

      REM call stored procedure From MYSQL server
      del "C:Users7642FHLocalfileTest.sql"
      ECHO USE pce; > C:Users7642FHLocalfileTest.sql
      ECHO LOAD DATA LOCAL INFILE '!FILEPATHSQL!' >> C:Users7642FHLocalfileTest.sql
      ECHO !TBL! >> C:Users7642FHLocalfileTest.sql
      ECHO FIELDS TERMINATED BY ";" >> C:Users7642FHLocalfileTest.sql
      ECHO LINES TERMINATED BY '
' >> C:Users7642FHLocalfileTest.sql
      ECHO IGNORE 1 ROWS >> C:Users7642FHLocalfileTest.sql
      SET "VAR=(@var1,@var2,@var3)"
      ECHO !VAR! >> C:Users7642FHLocalfileTest.sql
      ECHO !SQL! >> C:Users7642FHLocalfileTest.sql
      CALL %MYSQL_EXE% --user=%DB_USER% --password=%DB_PWD% --database=%DB%    < C:Users7642FHLocalfileTest.sql

)

And my sql


USE pce;
LOAD DATA LOCAL INFILE 'C:/Users/7642FH/Local/RawFile/20141018/PREV_PCE_20141018_20141013_092802.csv' 
INTO TABLE tbl_pceraw
FIELDS TERMINATED BY ";"
LINES TERMINATED BY '
' 
IGNORE 1 ROWS
(@var1, @var2, @var3)
SET ElementId=@var1, TargetDateTime=!!,  CurrValue = REPLACE(@var3, ',', '.'), DataType='Actual', `TargetDate``TargetDateFolder``ComputeDateTime``ForcastValue``TargetFolder`;

I hope that it could be useful for someone !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use MySQL command with an e option

Command

mysql -uDBUserName -pUserPassword -DDBName -e="CALL stored_procedure_name (param1, param2, ....)"

Check this


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...