Oracle database tips logo
Article categories | Blog and News Page | SQL | SQL*Plus | DBA Scripts | Standby dbs | Database Links | Techno webcasts | Oracle Magazine | Free IT Magazines | Oracle Database Hosting Companies | Site Search |
RSS
XML RSS
What is this?
AddThis Feed Button

Social Bookmarking


-- FREE --
IT Magazine
Subscriptions

Oracle Magazine Oracle Magazine Contains technology strategy articles, sample code, tips, Oracle and partner news, how-to articles for developers and DBAs

WebSite Magazine WebSite Magazine Practical advice, helpful tools and insights for website owners

Dr Dobb's Journal Dr Dobb's Journal enables coders to write the most efficient programs and help in daily programming quandaries

DM Review DM Review is recognized as the premier business intelligence, analytics and data warehousing publication
Various other Free IT magazine subscriptions
NoAdware Free Trial

NoAdware Remove
harmful
adware,
spyware,
trojans,
dialers
and worms!
- Featured ebook -

Database Normalization
by Alf Pedersen

Database Normalization ebook Understand and master how to normalize a database using methods richly documented with graphical ERD and server diagram examples

Sqlplus BindVariables
An example script



Always test these 'sqlplus bindvariables' commands on a test server before implementing them on a production server.

Below is an example script (check_stby.sql) which I've used to compare the most
recently applied archive log file at a standby database to the most recently archived log
at the primary database.
(I know, DataGuard can do this for me with much less effort..)

I am using sql*plus bind variables because I needed to connect to 2 different databases
and compare their results.
The standby database is in mounted mode, so this precludes the idea of trying to get this information
across a database link.

The sql script is then called by a shell script. (check_stby.sh) which gets called by
a host-user-defined-metric in Enterprise Manager's Grid Control system.

If the returned value exceeds the metric's threshold, an alert is triggered and I receive an
email warning me to check the status of the standby database.

check_stby.sql


set echo off
set feedback off
set termout off
VARIABLE prim_seq NUMBER
variable stby_seq number
variable diff number

connect sys/xxxx@primarydb.world.com as sysdba
begin
select max(sequence#)into :prim_seq from v$archived_log;
end;
/

connect sys/xxxx@standbydb.world.com as sysdba
begin
select max(sequence#) into :stby_seq from v$log_history;
end;
/

begin
:diff := :prim_seq - :stby_seq   ;
end;
/
exit :diff;


check_stby.sh


#!/bin/ksh

export ORACLE_HOME=/home/oracle/product/10.2.0

$ORACLE_HOME/bin/sqlplus -s /nolog @check_stby.sql

echo "em_result="$?"\n"



Recommended reading:

  • Oracle Online Documentation : SQL*PlusŪ User's Guide and Reference, Using Bind Variables


  • Return from 'sqlplus bindvariables' back to 'oracle sqlplus tutorials'