0

以下代码用于通过批处理文件连接到 Oracle 数据库,提示输入用户名、密码和数据库实例。如果任何凭据无效,我想要的是退出 cmd 本身,否则它应该正常进行。

@ECHO OFF
:START
set /p U="Enter Username(User ID):"
set /p P="Enter Password(Password@o1234abc):
:NEXT
set /p a="Do you want to display details of 1a?(y/n)"
ECHO "%a%"
if "%a%" == "y" sqlplus %U%/%P% @".\AB_1a.sql" 
if "%a%" == "n" goto A 
set /p id1= "Please enter ID for 1a(press 's' to SKIP):"
if "%id1%" == "s" goto A 
sqlplus %U%/%P% @".\AB_.sql" %id1%
goto A
:End

请提出任何解决方案。

4

1 回答 1

1

你可以这样做:

@echo off
setlocal enableDelayedExpansion
set /p U="Enter Username(User ID):" 
set /p P="Enter Password(Password@o1234abc):
rem Check creds!
if "!U!" == "JoeBloggs" if "!P!" == "Pa$$w0rd" goto :CREDSOK
exit >nul

:CREDSOK
set /p a="Do you want to display details of 1a?(y/n)" 
if "%a%" == "y" sqlplus %U%/%P% @".\AB_1a.sql"  
if "%a%" == "n" goto A  
set /p id1= "Please enter ID for 1a(press 's' to SKIP):" 
if "%id1%" == "s" goto A  
sqlplus %U%/%P% @".\AB_.sql" %id1% 
goto A 
:End

如果凭据正确,它将跳过该行退出并运行其余部分,如果任何一个凭据错误,它将到达退出行并终止 cmd。

感谢@jeb 建议延迟扩展特殊字符,请参阅下面的评论。

希望这可以帮助。

于 2012-06-15T15:00:16.003 回答