Something as simple (and ugly) as the following might work:
@SET APPLY_ORA=YES
@REM ...
@echo off
IF %APPLY_ORA%==YES (
@ECHO Doing Oracle
@echo on
CALL %SOME_ORACLE_SPECIFIC_COMMAND% %SOME_ORACLE_SPECIFIC_FLAGS%
CALL %ANOTHER_ORACLE_SPECIFIC_COMMAND% %SOME_ORACLE_SPECIFIC_FLAGS%
@echo off
) ELSE (
@ECHO Skipping Oracle
)
I have also used code like the following to give much more control over when a command is displayed. It's come in very handy for debugging scripts that I normally don't want to have the commands displayed, but do want to display them when things go wrong (which is quite often with cmd scripts):
(set COMMAND="%PROG_FILES%\Microsoft Visual Studio\VC98\Bin\cl" /GX /Zi -D_WIN32_WINNT=%WIN32_WINNT% %SOURCE_FILE% /link /INCREMENTAL:NO %LIBRARIES%)
call :exec %COMMAND%
rem ...
rem exec - a subroutine that executes a command and optionally displays it first
rem depending on the value of the %ECHO_COMMANDLINE% variable
:exec
if {%ECHO_COMMANDLINE%} == {1} (
echo %*
)
%*
goto :eof
If you want to execute a command after displaying the command unconditionally, the following version of your script uses a simple variation of the above that does the trick:
@echo off
set SOME_ORACLE_SPECIFIC_COMMAND=ftype
set SOME_ORACLE_SPECIFIC_FLAGS=txtfile
set ANOTHER_ORACLE_SPECIFIC_COMMAND=dir
SET APPLY_ORA=YES
REM ...
IF %APPLY_ORA%==YES (
ECHO Doing Oracle
call :echoexec %SOME_ORACLE_SPECIFIC_COMMAND% %SOME_ORACLE_SPECIFIC_FLAGS%
call :echoexec %ANOTHER_ORACLE_SPECIFIC_COMMAND% %SOME_ORACLE_SPECIFIC_FLAGS%
) ELSE (
ECHO Skipping Oracle
)
rem done with the script
goto :eof
rem - subroutines
@rem echoexec - a subroutine that executes a command also displaying
@rem the command that's about to be exectued
:echoexec
@echo %*
@%*
@goto :eof
Finally, you mention that you want to determine the current state of the "echo" command. It's a little tricky because the "echo" command is a built-in intrinsic part of cmd.exe, and not a separate executable file (at least that's what I think makes it tricky). Here's a script that has a subroutine you can use to query the current "echo" status (as well as some commands that test/demonstrate it):
@rem - examples of using the "echo_state" subroutine
@echo
@call :get_echo_state
@echo echo state was %RET%
@echo off
@echo
@call :get_echo_state
@echo echo state was %RET%
@echo on
@echo
@call :get_echo_state
@echo echo state was %RET%
@goto :eof
@rem
@rem echo_state - returns the current state of the script's echo setting
@rem
@rem upon return, the environment variable RET will contian the word
@rem 'off' if echo is currently off and 'on' if it's on. It does this
@rem by parsing the output of the 'echo' command redirected ot a file.
@rem
@rem For some reason I find that it's necessary to redirect to a file
@rem to parse the state, becuase if I try to parse the output of
@rem the 'echo' command directly in the "for /f" command like so:
@rem
@rem @for /f "tokens=3" %%a in ('echo') do @if "%%a" == "on." set RET=on
@rem
@rem it always returns that echo is "on" (I suspect this has something to
@rem with the 'echo' command being a builtin part of cmd.exe and not
@rem an external command, but I'm not sure).
@rem
:get_echo_state
@setlocal
@echo > %temp%\echostate.txt
@set RET=off
@for /f "tokens=3" %%a in (%temp%\echostate.txt) do @if "%%a" == "on." set RET=on
@endlocal & set RET=%RET%
@goto :eof
Personally, I like to immediately set "echo off" at the start of my scripts and use the technique in the my second script above (the 'exec' subroutine) to run a command that might have the command line displayed. I imagine that turning the echo state on and off throughout the script would be a pain to manage.