Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

batch file to open sqlplus

Posted on 2011-09-27
2
777 Views
Last Modified: 2012-08-14
Hi,

I have a dozens of batch files that I use to automate SQLPlus (and SQLCMD).  I need to change my db passwords frequently, and updating all of my batch files is a big pain.  

Could I store the pw in a single place and call it from the batch file?

Here's what a current sqlplus batch file looks like:
chdir "O:\Automation"
sqlplus user/passwrd@db @example.sql

what I'd like to have is only one file that contains my password
something like C:\securefolder\password.txt

Can I reference that in the batch file to get the pw?

Thanks!
0
Comment
Question by:TelMaco
  • 2
2 Comments
 

Accepted Solution

by:
TelMaco earned 0 total points
ID: 36713741
I found a solution here:
www.computing.net

I took the suggestion from klint and modified it to this:
@echo off
setlocal enabledelayedexpansion
set ConStr=
for /f "delims=" %%a in (mydb_constr.txt) do (
  set currentline=%%a
  set ConStr=!ConStr!!currentline!
)

chdir "O:\Automation"

SET tns_admin=C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN

%ConStr%

cmd

Open in new window


Where the file (mydb_constr.txt) contains the connection string
"sqlplus user/passwrd@db @example.sql"
0
 

Author Comment

by:TelMaco
ID: 36717534
To clarlify in case anyone else finds this helpful...

I figured out how to make this work with just the pw, rather than the whole connection string.

I changed this line:
%ConStr%
to this:
!sqlplus user/%ConStr%@db @example.sql!

and then modified the .txt file to just store the pw

I didn't realize I could combine it all using the "%" symbol and tie it all in with the "!"

Looking back at the question I probably should have called this something like "referencing a variable in batch file" if a mod comes across this maybe you could change the title so others can find this easier?

Thanks EE!



0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question