Solved

How to automate sql script using cron job

Posted on 2007-12-04
5
5,812 Views
Last Modified: 2013-12-18
Dear experts -
I have to automate a sql script to run every day. I would like to know the various ways. I would prefer to do it using CRON. Please advice. Kind of urgent

regards
0
Comment
Question by:akp007
[X]
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
5 Comments
 
LVL 6

Assisted Solution

by:chedgey
chedgey earned 50 total points
ID: 20403786
What does your SQL script do?

If it a simple SQL script then the Oracle Job Scheduler is your best bet. See:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm#sthref6598

If the is controlled from a shell or Perl script then you can schedule it from CRON using by editiing Oracle's CRONTAB using the command "crontab -e".

Regards

chedgey
0
 

Author Comment

by:akp007
ID: 20403868
my script involves read from db and write to a table. I have an alter statement to change the optimizer setting. So it has alter,select and insert. I want to use shell for that. can you please provide me a some kind of script or idea, I can take it from there. Thanks for the fast response
regards
0
 
LVL 18

Assisted Solution

by:Jinesh Kamdar
Jinesh Kamdar earned 100 total points
ID: 20404027
Create a SQL script with ur DML / DDL statements. Next create a shell script that invokes the SQLPLUS with the SQL script. Another option is to create a stored procedure for your DDL / DML statements and schedule a DBMS_JOB to run it at periodic intervals.
0
 
LVL 35

Accepted Solution

by:
johnsone earned 350 total points
ID: 20406554
Below is a sample script that you could put into cron.  Remember that cron does not set the environment so you have to do it in the script.
#!/bin/sh
 
ORACLE_SID=<sid>
ORACLE_HOME=<ora_home>
PATH=${PATH}:${ORACLE_HOME}/bin
export ORACLE_SID ORACLE_HOME PATH
 
${ORACLE_HOME}/bin/sqlplus <user>/<pass> << END
-- Statements go here
exit
END

Open in new window

0
 

Author Comment

by:akp007
ID: 20414193
Thanks. I got an idea and now I am implementing it
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creation date for a PDB 5 63
capture vmstat info and insert it into an oracle table 31 62
Procedure syntax 5 50
update using pipeline function 3 34
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

730 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