开发者

Why does my if Else if statement not work in Batch script?

My Script

echo "Enter your choice (1 or 2 or 3) :"
set /p dbchoice=

IF %dbchoice EQU 1 ( 
    set dbtype="oracle"
) ELSE ( 
    IF %dbchoice EQU 2 ( 
        set dbtype="sqlserver" 
    )
) ELSE ( 
    IF %dbchoice EQU 3 ( 
        set dbtype="db2" 
  开发者_JS百科  )
) ELSE (
    echo "Incorrect choice" 
)

I get the following output:

E:\csmilm>set /p dbchoice=
1
ELSE was unexpected at this time.
E:\csmilm>) ELSE (
E:\csmilm>

What is the problem here?


Closing brackets in the wrong place. Try:

IF %dbchoice EQU 1 ( 
    set dbtype="oracle"
) ELSE ( 
    IF %dbchoice EQU 2 ( 
        set dbtype="sqlserver" 
    ) ELSE ( 
        IF %dbchoice EQU 3 ( 
            set dbtype="db2" 
        ) ELSE (
            echo "Incorrect choice" 
        )
    )
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜