Solved

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

Posted on 2008-06-18
5
1,464 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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wrap Oraccle SQL*Plus executable Command 4 84
C# Connection String for Oracle database is not working 22 145
Oracle dataguard 5 32
Oracle collections 15 23
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

810 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