Solved

How do I run an SQLPlus script to perform several Administration functions?

Posted on 2008-06-18
5
1,462 Views
Last Modified: 2012-05-05
HI,

     I have a few administrative commands I need to run against 3 different Oracle databases on the same instance. What is the syntax to connect to each db and execute commands via batch file?

connect to Database A
SQL>Revoke execute on UTL_FILE from Public;
SQL>Revoke execute on UTL_TCP from Public;
SQL>Alter user CTXSYS identified by Test12 account lock password expire;

connect to Database B
SQL>Revoke execute on UTL_FILE from Public;
SQL>Revoke execute on UTL_TCP from Public;
SQL>Alter user CTXSYS identified by Test12 account lock password expire;

Could you recommend a good link\book for running batch files in SQLPlus?

Thank You, Missymadi

0
Comment
Question by:missymadi
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 21817010
Here is the syntax

sqlplus /nolog <uid>/<pwd>@<instance> @<scriptpath>
0
 
LVL 3

Expert Comment

by:dalebetts
ID: 21817081
Create two files, one named admina.sql with the following:

Revoke execute on UTL_FILE from Public;
Revoke execute on UTL_TCP from Public;
Alter user CTXSYS identified by Test12 account lock password expire;

and one named adminb.sql with:

Revoke execute on UTL_FILE from Public;
Revoke execute on UTL_TCP from Public;
Alter user CTXSYS identified by Test12 account lock password expire;

And then to execute from the SQL prompt type:

@admina or @adminb

You have to ensure that files are in your current directory as you load sqlplus otherwise you have to supply the full path name for example if the files are store in C:\scripts

SQL> @C:\scripts\admina

You don't have to put the .sql suffix on the end of the filename when executing, it will work both ways.

Regards
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 21817101
dalebetts:
I think missymadi is asking to execute from Batch File
0
 
LVL 23

Expert Comment

by:David
ID: 21818695
Extending AJ's contribution:
#!/usr/bin/sh
sqlplus /nolog <uid>/<pwd>@<instanceA> <<EOF
Revoke execute on UTL_FILE from Public
/
Revoke execute on UTL_TCP from Public
/
Alter user CTXSYS identified by Test12 account lock password expire
/
EOF

And repeat as needed.  You might want to create a new question and learn how to pass the SID name as an argument to the batch file.
0
 
LVL 3

Accepted Solution

by:
dalebetts earned 125 total points
ID: 21821355
windows batch file?

The above would be no good in Windows environment. For windows just create test.bat, with:

set ORACLE_SID=<sid>
sqlplus username/password
Revoke execute on UTL_FILE from Public
/
Revoke execute on UTL_TCP from Public
/
Alter user CTXSYS identified by Test12 account lock password expire
/
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now