LoginSignup
0
2

More than 5 years have passed since last update.

sqlplusで複数SQLを確認しながら順に流し込むbat芸

Posted at

windows限定、超小ネタです。

1.流し込みたいSQLファイルの順番をリスト化したtxtファイルを用意

list.txt
hogehoge_alter.sql
hugahuga_insert.sql
mogamoga_update.sql

そもそも、このリストを作るのが辛いって人は

コマンドプロンプト
dir *.sql /b > list.txt

みたいな感じでlist.txtを出力させましょう。

2.以下内容のbatファイルに1.で作ったlistファイルをドラッグアンドドロップ

sqlplus_injection.bat
@echo off
set user=scott
set pass=tiger
set db=orcl
set SQLPLUS=sqlplus %user%/%pass%@%db% 

:init
cls
echo userを入力してください enter:%user%
set /p user=
if defined user set user=%user:"=%

echo passwordを入力してください enter:%pass%
set /p pass=
if defined pass set pass=%pass:"=%

echo dbの識別子をどうぞ enter:%db%
set /p db=
if defined db set db=%db:"=%

cls

echo user:%user%
echo password:%pass%
echo db:%db%
echo 以上の設定でよろしいですか? (やりなおし:0)

set /p input=
if defined input set input=%input:"=%
if /i "%input%" == "0" (goto init)

cls

FOR /F "" %%i IN (%1) DO @CALL :SUB %%i
goto Exit

:SUB
set args=%1
echo %args% の流し込み開始します。よろしいですか? (続ける:Enter 中止:0)
set /p input=
if defined input set input=%input:"=%
if /i "%input%" == "0" (goto Exit)
%SQLPLUS% < %args%
EXIT /B

:Exit
pause
exit

3.(゚д゚)ウマー

しかし、そろそろコマンドプロンプト(bat)芸も引退かな。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2