Here document

Jan 22, 2014
2
0
#1
Hi, just started using TC 16.0. Having problems with "Here Documents"

File ppp.bat works:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

sqlplus -L -S system/dwed7g << endtext
select name from v$database;
exit;
endtext

File zzz.bat does not work:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET ORACLE_BASE=G:\OPT\ORACLE
SET ORACLE_HOME=%ORACLE_BASE%\PRODUCT\112030
FOR /F %%A IN ('net start ^| findstr OracleService ^| sort') DO (
SET PIET=%%A
SET ORACLE_SID=%PIET:~13,10%
ECHO.
ECHO %ORACLE_SID%
sqlplus system/[email protected]%ORACLE_SID% << endtext
select username from dba_users;
exit;
endtext
)

Errors received:

PD4A
TCC: (Sys) C:\Temp\for_active_services.bat [19] De parameter is onjuist.
"C:\Users\ITCHAL~1\AppData\Local\Temp\Ein88E2.tmp"
TDB11203
TCC: (Sys) C:\Temp\for_active_services.bat [19] De parameter is onjuist.
"C:\Users\ITCHAL~1\AppData\Local\Temp\Ein8902.tmp"

Can somebody please advice?

Thanks

Peter
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,552
46
Albuquerque, NM
prospero.unm.edu
#2
Hi, just started using TC 16.0. Having problems with "Here Documents"

File zzz.bat does not work:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET ORACLE_BASE=G:\OPT\ORACLE
SET ORACLE_HOME=%ORACLE_BASE%\PRODUCT\112030
FOR /F %%A IN ('net start ^| findstr OracleService ^| sort') DO (
SET PIET=%%A
SET ORACLE_SID=%PIET:~13,10%
ECHO.
ECHO %ORACLE_SID%
sqlplus system/[email protected]%ORACLE_SID% << endtext
select username from dba_users;
exit;
endtext
)

Errors received:

PD4A
TCC: (Sys) C:\Temp\for_active_services.bat [19] De parameter is onjuist.
"C:\Users\ITCHAL~1\AppData\Local\Temp\Ein88E2.tmp"
TDB11203
TCC: (Sys) C:\Temp\for_active_services.bat [19] De parameter is onjuist.
"C:\Users\ITCHAL~1\AppData\Local\Temp\Ein8902.tmp"
I have no idea what that's supposed to do, but I do notice that you're posting a file named zzz.bat, while the error message refers to a file named "C:\Temp\for_active_services.bat". Maybe you should look at that file instead, particularly around line 19.
 
Jan 22, 2014
2
0
#3
I have no idea what that's supposed to do, but I do notice that you're posting a file named zzz.bat, while the error message refers to a file named "C:\Temp\for_active_services.bat". Maybe you should look at that file instead, particularly around line 19.
Hi, the name of the scripts is not important. I want to retrieve all services names called OracleService and then
cut character 13-23 from that name (this will retrieve a Oracle SID e.g. PD4A and this
will be placed in the variable ORACLE_SID).

For All these I want to execute an Oracle sqlplus process with a select statement.
This generates an error

Any ideas?

Thanks

Peter Jansen
 

samintz

Scott Mintz
May 20, 2008
1,269
11
Solon, OH, USA
#4
You are combining a single line statement (FOR) with a multi-line statement (here-document) and that will only confuse the parser.

try this instead:
Code:
do PIET in /p (net start | ffind /kmv /t"OracleService")
 SET ORACLE_SID=%@substr[%PIET,13,10]
 ECHO.
 ECHO %ORACLE_SID
 sqlplus system/[email protected]%ORACLE_SID <<<  select username from dba_users; exit;
enddo
Note that the above will not work in CMD or TCC/LE. It will only work in TCC.