<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Oracle Database Tips blog &#187; SQL*PLUS</title>
	<atom:link href="http://oracle-database-tips.com/wp/category/sqlplus/feed" rel="self" type="application/rss+xml" />
	<link>http://oracle-database-tips.com/wp</link>
	<description>News for Oracle professionals</description>
	<lastBuildDate>Fri, 03 Feb 2012 10:37:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Sqlplus Bindvariables</title>
		<link>http://oracle-database-tips.com/wp/sqlplus/sqlplus-bindvariables</link>
		<comments>http://oracle-database-tips.com/wp/sqlplus/sqlplus-bindvariables#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:25:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL*PLUS]]></category>
		<category><![CDATA[bind variables]]></category>
		<category><![CDATA[bindvariables syntax]]></category>
		<category><![CDATA[database check]]></category>
		<category><![CDATA[example script]]></category>
		<category><![CDATA[grid control]]></category>
		<category><![CDATA[script check]]></category>
		<category><![CDATA[sqlplus bindvariables]]></category>
		<category><![CDATA[standby database]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=88</guid>
		<description><![CDATA[sqlplus bindvariables example]]></description>
			<content:encoded><![CDATA[<p>Below is an example script (check_stby.sql)  which I&#8217;ve used to compare the most<br />
recently applied archive log file  at a standby database to the most recently archived log<br />
at the primary database.<br />
(I know, DataGuard can do this for me with much less effort..)</p>
<p>I am using sql*plus bind variables because I needed to connect  to 2 different databases<br />
and compare their results.<br />
The standby database is in mounted mode, so this precludes the idea of trying to get this information<br />
across a database link.</p>
<p>The sql script is then called by a shell script. (check_stby.sh) which gets called by<br />
a host-user-defined-metric in Enterprise Manager&#8217;s Grid Control system.</p>
<p>If the returned value exceeds the metric&#8217;s threshold, an alert is triggered and I receive an<br />
email warning me to check the status of the standby database.</p>
<h3>check_stby.sql</h3>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">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;</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3>check_stby.sh</h3>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">#!/bin/ksh

export ORACLE_HOME=/home/oracle/product/10.2.0

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

echo "em_result="$?"
"</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --> <!-- ============================================================================================================================================================ --></p>
<h3>Recommended reading:</h3>
<div id="content">
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14357%2Fch5.htm%23sthref1114&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Fsqlplus_bindvariables.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1114" target="_blank">Oracle Online Documentation : SQL*Plus® User&#8217;s Guide and Reference, Using Bind Variables</a></li>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sqlplus/sqlplus-bindvariables/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Demodrop.sql</title>
		<link>http://oracle-database-tips.com/wp/sqlplus/demodropsql</link>
		<comments>http://oracle-database-tips.com/wp/sqlplus/demodropsql#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:22:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL*PLUS]]></category>
		<category><![CDATA[bonus]]></category>
		<category><![CDATA[c oracle]]></category>
		<category><![CDATA[cascade]]></category>
		<category><![CDATA[demo folder]]></category>
		<category><![CDATA[demo tables]]></category>
		<category><![CDATA[demodrop.sql]]></category>
		<category><![CDATA[demonstration table]]></category>
		<category><![CDATA[dummy]]></category>
		<category><![CDATA[oracle corporation]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=85</guid>
		<description><![CDATA[demodrop.sql syntax]]></description>
			<content:encoded><![CDATA[<p>If you can&#8217;t find the sql script to drop the demo tables in your $ORACLE_HOME/sqlplus/demo folder<br />
(or %ORACLE_HOME%sqlplusdemo on windows)<br />
you can cut it from this page and paste it in a text editor of your choice.</p>
<p>Save it to a file on your server or PC and run it to complete dropping the Oracle demo tables.</p>
<h3>Demo_drop.sql</h3>
<p>====== start of section to cut ======</p>
<pre>--
-- Copyright (c) Oracle Corporation 1988, 2000.  All Rights Reserved.
--
--
-- DESCRIPTION
--   This script drops the SQL*Plus demonstration tables created by
--   demobld.sql.  It should be STARTed by each owner of the tables.
--
-- USAGE
--   From within SQL*Plus, enter:
--       START demodrop.sql

SET TERMOUT ON
PROMPT Dropping demonstration tables.  Please wait.
SET TERMOUT OFF

DROP TABLE EMP;
DROP TABLE DEPT;
DROP TABLE BONUS;
DROP TABLE SALGRADE;
DROP TABLE DUMMY;

SET TERMOUT ON
PROMPT Demonstration table drop is complete.

EXIT</pre>
<p>====== end of section to cut ======</p>
<h3>Drop scott user</h3>
<p>If you want to drop the scott user, do the following (login as DBA ):<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>SQL&gt; drop user scott cascade;</p>
<p>User dropped.</p></div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="content">
<li>The cascade word drops all objects owned by scott.</li>
<li>Make sure scott is no longer connected.</li>
<li>Only do this if you are sure you will no longer need the user or his objects.</li>
<li>Always take an export before dropping users.</li>
<p><!-- ============================================================================================================================================================ --></p>
<h3>Recommended reading:</h3>
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14357%2Ftoc.htm&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Fdemodrop.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/toc.htm" target="_blank">Oracle online documentation: SQL*Plus® User&#8217;s Guide and Reference</a></li>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sqlplus/demodropsql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Demobld.sql</title>
		<link>http://oracle-database-tips.com/wp/sqlplus/demobldsql</link>
		<comments>http://oracle-database-tips.com/wp/sqlplus/demobldsql#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:21:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL*PLUS]]></category>
		<category><![CDATA[dd]]></category>
		<category><![CDATA[demo table]]></category>
		<category><![CDATA[demobld]]></category>
		<category><![CDATA[demobld.sql]]></category>
		<category><![CDATA[oracle demo build]]></category>
		<category><![CDATA[oracle sqlplus]]></category>
		<category><![CDATA[table article]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=83</guid>
		<description><![CDATA[demobld.sql syntax]]></description>
			<content:encoded><![CDATA[<p>If you can&#8217;t find the demobld.sql in your $ORACLE_HOME/sqlplus/demo folder<br />
(or %ORACLE_HOME%sqlplusdemo on windows)<br />
you can cut it from this page and paste it in a text editor of your choice.</p>
<p>Save it to a file on your server or PC and follow the instructions in the<br />
<a title="opens new window" href="http://oracle-database-tips.com/wp/sqlplus/sqlplus-demo-table-setup" target="_blank">oracle sqlplus demo table article</a><br />
to complete building the Oracle demo tables.</p>
<h3>Demobld.sql</h3>
<p>====== start of section to cut ======</p>
<pre>--
-- Copyright (c) Oracle Corporation 1988, 2000.  All Rights Reserved.
--
-- NAME
--   demobld.sql
--
-- DESCRIPTION
--   This script creates the SQL*Plus demonstration tables in the
--   current schema.  It should be STARTed by each user wishing to
--   access the tables.  To remove the tables use the demodrop.sql
--   script.
--
--  USAGE
--    From within SQL*Plus, enter:
--        START demobld.sql

SET TERMOUT ON
PROMPT Building demonstration tables.  Please wait.
SET TERMOUT OFF

DROP TABLE EMP;
DROP TABLE DEPT;
DROP TABLE BONUS;
DROP TABLE SALGRADE;
DROP TABLE DUMMY;

CREATE TABLE EMP
       (EMPNO NUMBER(4) NOT NULL,
        ENAME VARCHAR2(10),
        JOB VARCHAR2(9),
        MGR NUMBER(4),
        HIREDATE DATE,
        SAL NUMBER(7, 2),
        COMM NUMBER(7, 2),
        DEPTNO NUMBER(2));

INSERT INTO EMP VALUES
        (7369, 'SMITH',  'CLERK',     7902,
        TO_DATE('17-DEC-1980', 'DD-MON-YYYY'),  800, NULL, 20);
INSERT INTO EMP VALUES
        (7499, 'ALLEN',  'SALESMAN',  7698,
        TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600,  300, 30);
INSERT INTO EMP VALUES
        (7521, 'WARD',   'SALESMAN',  7698,
        TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250,  500, 30);
INSERT INTO EMP VALUES
        (7566, 'JONES',  'MANAGER',   7839,
        TO_DATE('2-APR-1981', 'DD-MON-YYYY'),  2975, NULL, 20);
INSERT INTO EMP VALUES
        (7654, 'MARTIN', 'SALESMAN',  7698,
        TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);
INSERT INTO EMP VALUES
        (7698, 'BLAKE',  'MANAGER',   7839,
        TO_DATE('1-MAY-1981', 'DD-MON-YYYY'),  2850, NULL, 30);
INSERT INTO EMP VALUES
        (7782, 'CLARK',  'MANAGER',   7839,
        TO_DATE('9-JUN-1981', 'DD-MON-YYYY'),  2450, NULL, 10);
INSERT INTO EMP VALUES
        (7788, 'SCOTT',  'ANALYST',   7566,
        TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
INSERT INTO EMP VALUES
        (7839, 'KING',   'PRESIDENT', NULL,
        TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);
INSERT INTO EMP VALUES
        (7844, 'TURNER', 'SALESMAN',  7698,
        TO_DATE('8-SEP-1981', 'DD-MON-YYYY'),  1500,    0, 30);
INSERT INTO EMP VALUES
        (7876, 'ADAMS',  'CLERK',     7788,
        TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);
INSERT INTO EMP VALUES
        (7900, 'JAMES',  'CLERK',     7698,
        TO_DATE('3-DEC-1981', 'DD-MON-YYYY'),   950, NULL, 30);
INSERT INTO EMP VALUES
        (7902, 'FORD',   'ANALYST',   7566,
        TO_DATE('3-DEC-1981', 'DD-MON-YYYY'),  3000, NULL, 20);
INSERT INTO EMP VALUES
        (7934, 'MILLER', 'CLERK',     7782,
        TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);

CREATE TABLE DEPT
       (DEPTNO NUMBER(2),
        DNAME VARCHAR2(14),
        LOC VARCHAR2(13) );

INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK');
INSERT INTO DEPT VALUES (20, 'RESEARCH',   'DALLAS');
INSERT INTO DEPT VALUES (30, 'SALES',      'CHICAGO');
INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON');

CREATE TABLE BONUS
        (ENAME VARCHAR2(10),
         JOB   VARCHAR2(9),
         SAL   NUMBER,
         COMM  NUMBER);

CREATE TABLE SALGRADE
        (GRADE NUMBER,
         LOSAL NUMBER,
         HISAL NUMBER);

INSERT INTO SALGRADE VALUES (1,  700, 1200);
INSERT INTO SALGRADE VALUES (2, 1201, 1400);
INSERT INTO SALGRADE VALUES (3, 1401, 2000);
INSERT INTO SALGRADE VALUES (4, 2001, 3000);
INSERT INTO SALGRADE VALUES (5, 3001, 9999);

CREATE TABLE DUMMY
        (DUMMY NUMBER);

INSERT INTO DUMMY VALUES (0);

COMMIT;

SET TERMOUT ON
PROMPT Demonstration table build is complete.

EXIT</pre>
<p>====== end of section to cut ======<br />
<!-- ============================================================================================================================================================ --></p>
<h3>Recommended reading:</h3>
<div id="content">
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14357%2Ftoc.htm&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Fdemobld.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/toc.htm" target="_blank">Oracle online documentation: SQL*Plus® User&#8217;s Guide and Reference</a></li>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sqlplus/demobldsql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sqlplus demo table setup</title>
		<link>http://oracle-database-tips.com/wp/sqlplus/sqlplus-demo-table-setup</link>
		<comments>http://oracle-database-tips.com/wp/sqlplus/sqlplus-demo-table-setup#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:18:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL*PLUS]]></category>
		<category><![CDATA[default user]]></category>
		<category><![CDATA[oracle demo setup]]></category>
		<category><![CDATA[sql script]]></category>
		<category><![CDATA[sqlplus demo setup]]></category>
		<category><![CDATA[table creation]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=81</guid>
		<description><![CDATA[Sqlplus demo table setup]]></description>
			<content:encoded><![CDATA[<p>Create scott and run the oracle sqlplus demo table creation script<br />
by following the instructions below.</p>
<p>Scott is the standard example schema used to run queries and scripts to show how Oracle works.</p>
<h3>Scott schema creation.</h3>
<p>Create the <strong>scott</strong> user on your database if it does not already exist.</p>
<p>Connect to the database as a dba user, like sys or system.</p>
<div id="textbox">
<div>SQL&gt; create user scott identified by tiger<br />
default tablespace users temporary tablespace temp profile default;</p>
<p>User created.</p>
<p>SQL&gt; grant connect, resource to scott;</p>
<p>Grant succeeded.</p>
<p>SQL&gt; alter user scott account unlock;</p>
<p>User altered.</p></div>
</div>
<h3>Demobuild execution.</h3>
<p>The script to create the tables (<a href="http://oracle-database-tips.com/wp/sqlplus/demobldsql">demobld.sql</a>) is located in<br />
%oracle_home%sqlplusdemodemobld.sql<br />
or<br />
$ORACLE_HOME/sqlplus/demo/demobld.sql,<br />
for either windows or unix.</p>
<p>Depending on which version of Oracle you use, it will create the following tables:</p>
<ul>
<li>EMP</li>
<li>DEPT</li>
<li>BONUS</li>
<li>SALGRADE</li>
<li>DUMMY</li>
</ul>
<p>How to run it:</p>
<div id="textbox">
<div>SQL&gt; connect scott/tiger<br />
Connected.</p>
<p>SQl&gt; @?/sqlplus/demo/demobld.sql<br />
Building demonstration tables.  Please wait.<br />
Demonstration table build is complete.</p></div>
</div>
<p>To drop the demo tables, run the <a href="http://oracle-database-tips.com/wp/sqlplus/demodropsql">demodrop.sql</a> script in the same directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sqlplus/sqlplus-demo-table-setup/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

