Tuesday, December 16, 2014

ORA-01113: file 5 needs media recovery

SQL> ALTER TABLESPACE TEST_USER ONLINE;
ALTER TABLESPACE TEST_USER ONLINE
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: 'D:\APP\ORADATA\DBRMAN\TEST_USER01.DBF'


Elapsed: 00:00:00.10
SQL> RECOVER TABLESPACE TEST_USER;
ORA-00279: change 2227017 generated at 12/17/2014 12:21:31 needed for thread 1
ORA-00289: suggestion :
D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000002_0865847632.0001
ORA-00280: change 2227017 for thread 1 is in sequence #2


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

Log applied.
Media recovery complete.
SQL> ALTER TABLESPACE TEST_USER ONLINE;

Tablespace altered.

Elapsed: 00:00:00.46
SQL>

Sunday, December 14, 2014

Day Wise Account Balance Statement (Generat Manual Data Full Month).

CREATE TABLE AC_BAL
(
  AC_NUMBER  NUMBER,
  BALANCE    NUMBER,
  TR_DATE    DATE
);

SET DEFINE OFF;
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (1, 3000, TO_DATE('12/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (1, 2000, TO_DATE('12/04/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (1, 8000, TO_DATE('12/16/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (1, 5000, TO_DATE('12/29/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (2, 5000, TO_DATE('12/29/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (3, 200, TO_DATE('12/16/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;
------ Query For Generate Statement ---------------

SELECT B.AC_NUMBER, NVL(BALANCE,0) BALANCE, DAYS
FROM AC_BAL A RIGHT OUTER JOIN (SELECT DISTINCT AC_NUMBER,DAYS FROM AC_BAL, (
SELECT (CASE WHEN LEVEL>1 THEN TRUNC(TO_DATE('30-DEC-2014'),'MM')+(LEVEL-1) ELSE TRUNC(TO_DATE('30-DEC-2014'),'MM')  END) DAYS
FROM   DUAL
CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY('30-DEC-2014'),'DD')))
ORDER BY AC_NUMBER) B
ON (A.TR_DATE=B.DAYS AND B.AC_NUMBER=A.AC_NUMBER)
ORDER BY B.AC_NUMBER, DAYS

Friday, December 12, 2014

ORA-38706: Cannot turn on FLASHBACK DATABASE logging.

SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-38706: Cannot turn on FLASHBACK DATABASE logging.
ORA-38707: Media recovery is not enabled.

Cause : For enable flashback database must be archive mode. To resolve this error enable archive log mode.

SQL>
SQL> STARTUP MOUNT;
ORACLE instance started.

Total System Global Area  630501376 bytes
Fixed Size                  2215984 bytes
Variable Size             381685712 bytes
Database Buffers          243269632 bytes
Redo Buffers                3330048 bytes
Database mounted.

SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /u01/app/oracle/oradata/archive
Oldest online log sequence     434
Current log sequence           436
SQL> alter database archivelog;

Database altered.

SQL> alter database flashback on;

Database altered.

SQL>

Monday, December 8, 2014

RMAN point in time Restore & Recovery.

1. STARTUP NOMOUNT PFILE='D:\app\oradata\DBRMAN_BACKUP\dbrman_pfile.ora';

2. RESTORE CONTROLFILE FROM 'D:\app\oradata\DBRMAN_BACKUP\BKP_DFDBRMAN_865846921_113_1_3HPPNHK9';

3. ALTER DATABASE MOUNT;

4. RUN
{
  ALLOCATE CHANNEL DISK1 TYPE DISK;
  SET UNTIL TIME "to_date('2014-12-09:09:02:00', 'yyyy-mm-dd:hh24:mi:ss')";
  RESTORE DATABASE;
  RECOVER DATABASE;
};

C:\Users\rajib.pradhan>SET ORACLE_SID=DBRMAN
C:\Users\rajib.pradhan>RMAN TARGET/
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Dec 9 09:03:41 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: DBRMAN (DBID=3796675194)
RMAN> SHUTDOWN IMMEDIATE;
using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down
RMAN> STARTUP NOMOUNT PFILE='D:\app\oradata\DBRMAN_BACKUP\dbrman_pfile.ora';
connected to target database (not started)
Oracle instance started
Total System Global Area     535662592 bytes
Fixed Size                     1375792 bytes
Variable Size                377487824 bytes
Database Buffers             150994944 bytes
Redo Buffers                   5804032 bytes
RMAN> RESTORE CONTROLFILE FROM 'D:\app\oradata\DBRMAN_BACKUP\BKP_DFDBRMAN_865846921_113_1_3HPPNHK9';
Starting restore at 09-DEC-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=63 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=D:\APP\ORADATA\DBRMAN\CONTROL01.CTL
Finished restore at 09-DEC-14
RMAN> ALTER DATABASE MOUNT;
database mounted
released channel: ORA_DISK_1
RMAN> RUN
2> {
3>   ALLOCATE CHANNEL DISK1 TYPE DISK;
4>   SET UNTIL TIME "to_date('2014-12-09:09:02:00', 'yyyy-mm-dd:hh24:mi:ss')";
5>   RESTORE DATABASE;
6>   RECOVER DATABASE;
7> };

allocated channel: DISK1
channel DISK1: SID=63 device type=DISK
executing command: SET until clause
Starting restore at 09-DEC-14
Starting implicit crosscheck backup at 09-DEC-14
Crosschecked 24 objects
Finished implicit crosscheck backup at 09-DEC-14
Starting implicit crosscheck copy at 09-DEC-14
Finished implicit crosscheck copy at 09-DEC-14
searching for all files in the recovery area
cataloging files...
no files cataloged

channel DISK1: starting datafile backup set restore
channel DISK1: specifying datafile(s) to restore from backup set
channel DISK1: restoring datafile 00001 to D:\APP\ORADATA\DBRMAN\SYSTEM01.DBF
channel DISK1: restoring datafile 00002 to D:\APP\ORADATA\DBRMAN\SYSAUX01.DBF
channel DISK1: restoring datafile 00003 to D:\APP\ORADATA\DBRMAN\UNDOTBS01.DBF
channel DISK1: restoring datafile 00004 to D:\APP\ORADATA\DBRMAN\USERS01.DBF
channel DISK1: restoring datafile 00005 to D:\APP\ORADATA\DBRMAN\CATALOG_SPC01.DBF
channel DISK1: restoring datafile 00006 to D:\APP\ORADATA\DBRMAN\TBS_RAMN_CAT_01.DBF
channel DISK1: restoring datafile 00007 to D:\APP\ORADATA\DBRMAN\UNDOTBS02.DBF
channel DISK1: restoring datafile 00010 to D:\APP\ORADATA\DBRMAN\EXAMPLE01.DBF
channel DISK1: reading from backup piece D:\APP\ORADATA\DBRMAN_BACKUP\BKP_DFDBRMAN_865846474_112_1_3GPPNH6A
channel DISK1: piece handle=D:\APP\ORADATA\DBRMAN_BACKUP\BKP_DFDBRMAN_865846474_112_1_3GPPNH6A tag=TAG20141209T085434
channel DISK1: restored backup piece 1
channel DISK1: restore complete, elapsed time: 00:01:55
Finished restore at 09-DEC-14
Starting recover at 09-DEC-14
starting media recovery
archived log for thread 1 with sequence 218 is already on disk as file D:\APP\ORADATA\DBRMAN\REDO02.LOG
archived log file name=D:\APP\ORADATA\DBRMAN\REDO02.LOG thread=1 sequence=218
media recovery complete, elapsed time: 00:00:02
Finished recover at 09-DEC-14
released channel: DISK1
RMAN> ALTER DATABASE OPEN RESETLOGS;
database opened
RMAN>

RMAN-06059: expected archived log not found

To resolved this error we need to check all archive log file validity, if any archive log file expire then we need to delete expire archive log files.

CROSSCHECK ARCHIVELOG ALL;
DELETE EXPIRED ARCHIVELOG ALL;

RMAN> BACKUP DATABASE PLUS ARCHIVELOG DELETE INPUT;

Starting backup at 09-DEC-14
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=131 device type=DISK
skipping archived log file D:\APP\ORADATA\ARC0000000187_0850433149.0001; already backed up 1 time(s)
skipping archived log file D:\APP\ORADATA\ARC0000000188_0850433149.0001; already backed up 1 time(s)
skipping archived log file D:\APP\ORADATA\ARC0000000189_0850433149.0001; already backed up 1 time(s)
skipping archived log file D:\APP\ORADATA\ARC0000000190_0850433149.0001; already backed up 1 time(s)
skipping archived log file D:\APP\ORADATA\ARC0000000191_0850433149.0001; already backed up 1 time(s)
skipping archived log file D:\APP\ORADATA\ARC0000000192_0850433149.0001; already backed up 1 time(s)
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup plus archivelog command at 12/09/2014 08:51:19
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability
ORA-19625: error identifying file
D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000193_0850433149.0001
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.

RMAN> crosscheck archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=131 device type=DISK
validation failed for archived log
archived log file name=D:\APP\ORADATA\ARC0000000187_0850433149.0001 RECID=201 STAMP=858860317
validation failed for archived log
archived log file name=D:\APP\ORADATA\ARC0000000188_0850433149.0001 RECID=202 STAMP=858860320
validation failed for archived log
archived log file name=D:\APP\ORADATA\ARC0000000189_0850433149.0001 RECID=203 STAMP=858860322
validation failed for archived log
archived log file name=D:\APP\ORADATA\ARC0000000190_0850433149.0001 RECID=204 STAMP=858860324
validation failed for archived log
archived log file name=D:\APP\ORADATA\ARC0000000191_0850433149.0001 RECID=205 STAMP=858860325
validation failed for archived log
archived log file name=D:\APP\ORADATA\ARC0000000192_0850433149.0001 RECID=206 STAMP=858860325
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000193_0850433149.0001 RECID=200 STAMP=858814156
validation failed for archived log
archived log file name=D:\APP\ORADATA\ARC0000000194_0850433149.0001 RECID=207 STAMP=858860367
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000195_0850433149.0001 RECID=208 STAMP=858860584
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000196_0850433149.0001 RECID=209 STAMP=858866846
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000197_0850433149.0001 RECID=210 STAMP=858866860
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000198_0850433149.0001 RECID=211 STAMP=858866871
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000199_0850433149.0001 RECID=212 STAMP=858866884
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000200_0850433149.0001 RECID=213 STAMP=858866895
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000201_0850433149.0001 RECID=214 STAMP=858866904
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000202_0850433149.0001 RECID=215 STAMP=858866913
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000203_0850433149.0001 RECID=216 STAMP=858866922
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000204_0850433149.0001 RECID=217 STAMP=858866933
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000205_0850433149.0001 RECID=218 STAMP=858866943
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000206_0850433149.0001 RECID=219 STAMP=858866953
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000207_0850433149.0001 RECID=220 STAMP=858866961
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000208_0850433149.0001 RECID=221 STAMP=858866973
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000209_0850433149.0001 RECID=222 STAMP=858867029
validation failed for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000210_0850433149.0001 RECID=223 STAMP=858867130
validation succeeded for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000211_0850433149.0001 RECID=224 STAMP=860501773
validation succeeded for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000212_0850433149.0001 RECID=225 STAMP=860502147
validation succeeded for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000213_0850433149.0001 RECID=226 STAMP=861363186
validation succeeded for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000214_0850433149.0001 RECID=227 STAMP=865814407
validation succeeded for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000215_0850433149.0001 RECID=228 STAMP=865846157
validation succeeded for archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000216_0850433149.0001 RECID=229 STAMP=865846276
Crosschecked 30 objects

RMAN> delete expired archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=131 device type=DISK
List of Archived Log Copies for database with db_unique_name DBRMAN
=====================================================================
Key     Thrd Seq     S Low Time
------- ---- ------- - ---------
201     1    187     X 20-SEP-14
        Name: D:\APP\ORADATA\ARC0000000187_0850433149.0001
202     1    188     X 20-SEP-14
        Name: D:\APP\ORADATA\ARC0000000188_0850433149.0001
203     1    189     X 20-SEP-14
        Name: D:\APP\ORADATA\ARC0000000189_0850433149.0001
204     1    190     X 20-SEP-14
        Name: D:\APP\ORADATA\ARC0000000190_0850433149.0001
205     1    191     X 20-SEP-14
        Name: D:\APP\ORADATA\ARC0000000191_0850433149.0001
206     1    192     X 20-SEP-14
        Name: D:\APP\ORADATA\ARC0000000192_0850433149.0001
200     1    193     X 20-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000193_0850433149.0001
207     1    194     X 20-SEP-14
        Name: D:\APP\ORADATA\ARC0000000194_0850433149.0001
208     1    195     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000195_0850433149.0001
209     1    196     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000196_0850433149.0001
210     1    197     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000197_0850433149.0001
211     1    198     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000198_0850433149.0001
212     1    199     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000199_0850433149.0001
213     1    200     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000200_0850433149.0001
214     1    201     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000201_0850433149.0001
215     1    202     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000202_0850433149.0001
216     1    203     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000203_0850433149.0001
217     1    204     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000204_0850433149.0001
218     1    205     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000205_0850433149.0001
219     1    206     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000206_0850433149.0001
220     1    207     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000207_0850433149.0001
221     1    208     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000208_0850433149.0001
222     1    209     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000209_0850433149.0001
223     1    210     X 21-SEP-14
        Name: D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000210_0850433149.0001

Do you really want to delete the above objects (enter YES or NO)? YES
deleted archived log
archived log file name=D:\APP\ORADATA\ARC0000000187_0850433149.0001 RECID=201 STAMP=858860317
deleted archived log
archived log file name=D:\APP\ORADATA\ARC0000000188_0850433149.0001 RECID=202 STAMP=858860320
deleted archived log
archived log file name=D:\APP\ORADATA\ARC0000000189_0850433149.0001 RECID=203 STAMP=858860322
deleted archived log
archived log file name=D:\APP\ORADATA\ARC0000000190_0850433149.0001 RECID=204 STAMP=858860324
deleted archived log
archived log file name=D:\APP\ORADATA\ARC0000000191_0850433149.0001 RECID=205 STAMP=858860325
deleted archived log
archived log file name=D:\APP\ORADATA\ARC0000000192_0850433149.0001 RECID=206 STAMP=858860325
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000193_0850433149.0001 RECID=200 STAMP=858814156
deleted archived log
archived log file name=D:\APP\ORADATA\ARC0000000194_0850433149.0001 RECID=207 STAMP=858860367
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000195_0850433149.0001 RECID=208 STAMP=858860584
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000196_0850433149.0001 RECID=209 STAMP=858866846
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000197_0850433149.0001 RECID=210 STAMP=858866860
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000198_0850433149.0001 RECID=211 STAMP=858866871
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000199_0850433149.0001 RECID=212 STAMP=858866884
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000200_0850433149.0001 RECID=213 STAMP=858866895
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000201_0850433149.0001 RECID=214 STAMP=858866904
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000202_0850433149.0001 RECID=215 STAMP=858866913
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000203_0850433149.0001 RECID=216 STAMP=858866922
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000204_0850433149.0001 RECID=217 STAMP=858866933
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000205_0850433149.0001 RECID=218 STAMP=858866943
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000206_0850433149.0001 RECID=219 STAMP=858866953
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000207_0850433149.0001 RECID=220 STAMP=858866961
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000208_0850433149.0001 RECID=221 STAMP=858866973
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000209_0850433149.0001 RECID=222 STAMP=858867029
deleted archived log
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000210_0850433149.0001 RECID=223 STAMP=858867130
Deleted 24 EXPIRED objects
RMAN> BACKUP DATABASE PLUS ARCHIVELOG DELETE INPUT;

Starting backup at 09-DEC-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=211 RECID=224 STAMP=860501773
input archived log thread=1 sequence=212 RECID=225 STAMP=860502147
input archived log thread=1 sequence=213 RECID=226 STAMP=861363186
input archived log thread=1 sequence=214 RECID=227 STAMP=865814407
input archived log thread=1 sequence=215 RECID=228 STAMP=865846157
input archived log thread=1 sequence=216 RECID=229 STAMP=865846276
input archived log thread=1 sequence=217 RECID=230 STAMP=865846456
channel ORA_DISK_1: starting piece 1 at 09-DEC-14
channel ORA_DISK_1: finished piece 1 at 09-DEC-14
piece handle=D:\APP\ORADATA\DBRMAN_BACKUP\BKP_DFDBRMAN_865846457_111_1_3FPPNH5P tag=TAG20141209T085417 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16
channel ORA_DISK_1: deleting archived log(s)
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000211_0850433149.0001 RECID=224 STAMP=860501773
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000212_0850433149.0001 RECID=225 STAMP=860502147
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000213_0850433149.0001 RECID=226 STAMP=861363186
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000214_0850433149.0001 RECID=227 STAMP=865814407
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000215_0850433149.0001 RECID=228 STAMP=865846157
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000216_0850433149.0001 RECID=229 STAMP=865846276
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000217_0850433149.0001 RECID=230 STAMP=865846456
Finished backup at 09-DEC-14
Starting backup at 09-DEC-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=D:\APP\ORADATA\DBRMAN\USERS01.DBF
input datafile file number=00001 name=D:\APP\ORADATA\DBRMAN\SYSTEM01.DBF
input datafile file number=00005 name=D:\APP\ORADATA\DBRMAN\CATALOG_SPC01.DBF
input datafile file number=00006 name=D:\APP\ORADATA\DBRMAN\TBS_RAMN_CAT_01.DBF
input datafile file number=00002 name=D:\APP\ORADATA\DBRMAN\SYSAUX01.DBF
input datafile file number=00003 name=D:\APP\ORADATA\DBRMAN\UNDOTBS01.DBF
input datafile file number=00010 name=D:\APP\ORADATA\DBRMAN\EXAMPLE01.DBF
input datafile file number=00007 name=D:\APP\ORADATA\DBRMAN\UNDOTBS02.DBF
channel ORA_DISK_1: starting piece 1 at 09-DEC-14
channel ORA_DISK_1: finished piece 1 at 09-DEC-14
piece handle=D:\APP\ORADATA\DBRMAN_BACKUP\BKP_DFDBRMAN_865846474_112_1_3GPPNH6A tag=TAG20141209T085434 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:07:25
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 09-DEC-14
channel ORA_DISK_1: finished piece 1 at 09-DEC-14
piece handle=D:\APP\ORADATA\DBRMAN_BACKUP\BKP_DFDBRMAN_865846921_113_1_3HPPNHK9 tag=TAG20141209T085434 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 09-DEC-14
Starting backup at 09-DEC-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=218 RECID=231 STAMP=865846923
channel ORA_DISK_1: starting piece 1 at 09-DEC-14
channel ORA_DISK_1: finished piece 1 at 09-DEC-14
piece handle=D:\APP\ORADATA\DBRMAN_BACKUP\BKP_DFDBRMAN_865846924_114_1_3IPPNHKC tag=TAG20141209T090203 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=D:\APP\ORADATA\DBRMAN_ARCHIVE\ARC0000000218_0850433149.0001 RECID=231 STAMP=865846923
Finished backup at 09-DEC-14
RMAN>

Sunday, November 30, 2014

Using Result Cache in Oracle 11g Database.

From Oracle 11g we can use result cache in function and query, these results is a faster response time. The cached results stored become invalid when data in the dependent database objects is changed. Result cache is instance specific. The Result Cache Memory pool consists of the SQL Query Result Cache and PL/SQL Function Result Cache, which stores the values returned by PL/SQL functions.

The RESULT_CACHE_MODE parameter determines the SQL query result cache behavior. This parameter contain MANUAL and FORCE. If you set manual you need to specify result_cache hint in your query. If set FORCE  all results use the cache, you can use no_result_cache hint to bypass the cache.

SQL> SET TIMING ON;
SQL> CREATE OR REPLACE FUNCTION RESULT_CASHE_TEST
  2  RETURN NUMBER
  3  RESULT_CACHE
  4  IS
  5  V_RETVALUE NUMBER:=0;
  6  BEGIN
  7
  8  FOR I IN 1 .. 5 LOOP
  9  DBMS_LOCK.sleep(1);
 10  V_RETVALUE:=V_RETVALUE*I;
 11  END LOOP;
 12
 13  RETURN V_RETVALUE;
 14  END ;
 15  /
Function created.
Elapsed: 00:00:00.01
SQL> SELECT RESULT_CASHE_TEST FROM DUAL;
RESULT_CASHE_TEST
-----------------
                0
Elapsed: 00:00:05.02
SQL> SELECT RESULT_CASHE_TEST FROM DUAL;
RESULT_CASHE_TEST
-----------------
                0
Elapsed: 00:00:00.00
SQL>
SQL> CREATE TABLE RESULT_CACHE( ID NUMBER, NAME VARCHAR2(300), SALARY NUMBER);
Table created.
Elapsed: 00:00:00.03
SQL> INSERT INTO RESULT_CACHE VALUES(10,'RAJIB.PRADHAN',5000);
1 row created.
Elapsed: 00:00:00.00
SQL> SELECT /*+ result_cache */  SALARY
  2  FROM RESULT_CACHE
  3  WHERE ID=10;
    SALARY
----------
      5000
Elapsed: 00:00:00.00
SQL>

Saturday, November 1, 2014

Delete Windows Service

1. First we need to identify which service we are going to delete.

2. Now delete service using sc delete "Service Name" command .

Now copy service name from properties 


Now delete service from cmd.



Set listener password in oracle database.

This is my listener 

SID_LIST_MYLISTENER=
  (SID_LIST=
(SID_DESC =
      (GLOBAL_DBNAME = ORCL)
      (ORACLE_HOME = D:\app\product\11.2.0\dbhome_1)
      (SID_NAME = ORCL)
    )
  )

MYLISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = N1020)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = D:\app

================================================


C:\Users\rajib.pradhan>lsnrctl

LSNRCTL for 32-bit Windows: Version 11.2.0.1.0 - Production on 02-NOV-2014 10:45:29

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Welcome to LSNRCTL, type "help" for information.
LSNRCTL> change_password MYLISTENER
Old password:
New password:
Reenter new password:
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
Password changed for LISTENER
The command completed successfully
LSNRCTL> save_config MYLISTENER
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
Saved MYLISTENER configuration parameters.
Listener Parameter File   D:\app\product\11.2.0\dbhome_1\network\admin\listener.ora
Old Parameter File   D:\app\product\11.2.0\dbhome_1\network\admin\listener.bak
The command completed successfully
LSNRCTL> status MYLISTENER
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     MYLISTENER
Version                   TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Production
Start Date                02-NOV-2014 10:51:24
Uptime                    0 days 0 hr. 2 min. 59 sec
Trace Level               off
Security                  ON: Password or Local OS Authentication
SNMP                      OFF
Listener Parameter File   D:\app\product\11.2.0\dbhome_1\network\admin\listener.ora
Listener Log File         d:\app\diag\tnslsnr\N1020\mylistener\alert\log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=N1020)(PORT=1521)))
Services Summary...
Service "ORCL" has 1 instance(s).
  Instance "ORCL", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
LSNRCTL> stop MYLISTENER
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
The command completed successfully
LSNRCTL> start MYLISTENER
Starting tnslsnr: please wait...

TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Production
System parameter file is D:\app\product\11.2.0\dbhome_1\network\admin\listener.ora
Log messages written to d:\app\diag\tnslsnr\N1020\mylistener\alert\log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=N1020)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     MYLISTENER
Version                   TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Production
Start Date                02-NOV-2014 10:54:40
Uptime                    0 days 0 hr. 0 min. 5 sec
Trace Level               off
Security                  ON: Password or Local OS Authentication
SNMP                      OFF
Listener Parameter File   D:\app\product\11.2.0\dbhome_1\network\admin\listener.ora
Listener Log File         d:\app\diag\tnslsnr\N1020\mylistener\alert\log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=N1020)(PORT=1521)))
Services Summary...
Service "ORCL" has 1 instance(s).
  Instance "ORCL", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

LSNRCTL>

-- After set listener password listener.ora file will be change with new parameter PASSWORDS_MYLISTENER Like this --------

#----ADDED BY TNSLSNR 02-NOV-2014 10:53:38---
PASSWORDS_MYLISTENER = 95286B9DA1A6B8FE

#--------------------------------------------



Thursday, October 30, 2014

Export/Generat user scripts in physical directory in Oracle Database.

In this article I am try to export user scripts in my physical directory. I have use an external table for maintain schema which I want to export.  


--- CREATING DIRECTORY FOR WRITE FILE

CREATE OR REPLACE DIRECTORY
DATA_DIR AS
'D:\DUMP\';

--- GRANT READ AND WRITE PERMITION TO SPECIFIC USER

GRANT READ, WRITE ON DIRECTIORY DATA_DIR TO TEST_USER;

-- CREATING EXTERNAL TABLE FOR COLLECT USER INFORMATION

CREATE TABLE EXT_TABLE
(
   USER_NAME         VARCHAR2 (200),
   REPLACE_ALLOWED   VARCHAR2 (10),
   COMMENTS          VARCHAR2 (300)
)
ORGANIZATION EXTERNAL
    (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY DATA_DIR
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
LOGFILE 'data.log'
BADFILE 'data.txt'
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
)
LOCATION('USER_REPLACE.csv')
)
REJECT LIMIT UNLIMITED;

-- CREATING PROCEDURE TO WRITE USER SCRIPTS

CREATE OR REPLACE PROCEDURE SP_USER_PRIVILEGES_SCRIPTS
(P_DIRECTORY VARCHAR2,P_FILE_NAME VARCHAR2)
IS
  V_CHNK_SIZE PLS_INTEGER;
  V_CLOB_USER CLOB;
  V_CLOB_DATA CLOB;
  V_OUTPUT UTL_FILE.FILE_TYPE;
  V_FILE_NAME VARCHAR2(1000);
 
  PROCEDURE USER_FILE_WRITE(P_WRITE_TAG VARCHAR2) IS
      BEGIN
        V_FILE_NAME:=P_FILE_NAME||'_'||P_WRITE_TAG||'.SQL';
        V_CLOB_DATA:=NULL;
       
        FOR INDUSR IN (SELECT USER_NAME  FROM EXT_TABLE WHERE REPLACE_ALLOWED='Y') LOOP

         BEGIN
            SELECT REPLACE(REPLACE(DBMS_METADATA.GET_DDL(P_WRITE_TAG, INDUSR.USER_NAME),'"',' '),'
 ','')||';'  INTO V_CLOB_USER
            FROM DUAL;
          END;
          V_CLOB_DATA:=V_CLOB_DATA||V_CLOB_USER;
         END LOOP;
        
          V_OUTPUT := UTL_FILE.FOPEN( P_DIRECTORY, V_FILE_NAME, 'wb', MAX_LINESIZE => 32767 );

          V_CHNK_SIZE := 3000;
          FOR I IN 1 .. CEIL( LENGTH( V_CLOB_DATA ) / V_CHNK_SIZE )
          LOOP
           
            UTL_FILE.PUT_RAW( V_OUTPUT, UTL_RAW.CAST_TO_RAW( SUBSTR( V_CLOB_DATA, ( I - 1 ) * V_CHNK_SIZE + 1, V_CHNK_SIZE ) ) );
             UTL_FILE.FFLUSH(V_OUTPUT);
          END LOOP;
       
          UTL_FILE.FCLOSE(V_OUTPUT);
     END;
    
   PROCEDURE GRANT_FILE_WRITE(P_WRITE_TAG VARCHAR2) IS
  BEGIN
    V_FILE_NAME:=P_FILE_NAME||'_'||P_WRITE_TAG||'.SQL';
    V_CLOB_DATA:=NULL;
 BEGIN
        FOR INDUSR IN (SELECT USER_NAME  FROM EXT_TABLE WHERE REPLACE_ALLOWED='Y') LOOP

         BEGIN
            SELECT REPLACE(REPLACE(REPLACE(DBMS_METADATA.GET_GRANTED_DDL(P_WRITE_TAG, INDUSR.USER_NAME),'"',' '),'
 ',';'),' . ','.')  INTO V_CLOB_USER
            FROM DUAL;
          END;
          V_CLOB_DATA:=V_CLOB_DATA||V_CLOB_USER;
         END LOOP;
  END;
  V_OUTPUT := UTL_FILE.FOPEN( P_DIRECTORY, V_FILE_NAME, 'wb', MAX_LINESIZE => 32767 );

  V_CHNK_SIZE := 3000;
  FOR I IN 1 .. CEIL( LENGTH( V_CLOB_DATA ) / V_CHNK_SIZE )
  LOOP
   
    UTL_FILE.PUT_RAW( V_OUTPUT, UTL_RAW.CAST_TO_RAW( SUBSTR( V_CLOB_DATA, ( I - 1 ) * V_CHNK_SIZE + 1, V_CHNK_SIZE ) ) );
    UTL_FILE.FFLUSH(V_OUTPUT);
  END LOOP;
  UTL_FILE.FCLOSE(V_OUTPUT);
 END;

 BEGIN

  USER_FILE_WRITE('USER');
  GRANT_FILE_WRITE('ROLE_GRANT');
  GRANT_FILE_WRITE('SYSTEM_GRANT');
  GRANT_FILE_WRITE('OBJECT_GRANT');
 
END;
/

-- EXECUTE PROCEDURE AND COLLECT SCRIPTS FROM DIRECTORIES

EXEC SP_USER_PRIVILEGES_SCRIPTS('DATA_DIR','TEST_SCRIPTS');

Export BLOB from database to physical directory.


 I have seen many people are failed to extract image from database to physical directory (in my article comments ) for this reason today I have make this procedure for export blob file.

You can export BLOB file using the following instruction.

1. Create an directory .

CREATE OR REPLACE DIRECTORY
DATA_DIR AS
'D:\DUMP\';

2. Create procedure.

CREATE OR REPLACE PROCEDURE SP_EXPORT_IMAGE (P_BLOB_DATA IN BLOB,P_FILE_NAME VARCHAR2,P_DIRECTORY VARCHAR2 )
AS
V_CLOB_DATA CLOB;
V_DATA VARCHAR2(32767);
V_START PLS_INTEGER := 1;
V_END PLS_INTEGER := 32767;
  V_OUTPUT UTL_FILE.FILE_TYPE;
  V_CHNK_SIZE PLS_INTEGER;
BEGIN
DBMS_LOB.CREATETEMPORARY(V_CLOB_DATA, TRUE);

FOR I IN 1..CEIL(DBMS_LOB.GETLENGTH(P_BLOB_DATA) / V_END)
LOOP

   V_DATA := UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(P_BLOB_DATA, V_END, V_START));

DBMS_LOB.WRITEAPPEND(V_CLOB_DATA, LENGTH(V_DATA), V_DATA);
V_START := V_START + V_END;
END LOOP;

V_CHNK_SIZE := 3000;

V_OUTPUT := UTL_FILE.FOPEN(P_DIRECTORY, P_FILE_NAME, 'wb', MAX_LINESIZE => 32767 );

  FOR I IN 1 .. CEIL( LENGTH( V_CLOB_DATA ) / V_CHNK_SIZE )
  LOOP
    UTL_FILE.PUT_RAW( V_OUTPUT, UTL_RAW.CAST_TO_RAW( SUBSTR( V_CLOB_DATA, ( I - 1 ) * V_CHNK_SIZE + 1, V_CHNK_SIZE ) ) );
    UTL_FILE.FFLUSH(V_OUTPUT);
  END LOOP;
       
  UTL_FILE.FCLOSE(V_OUTPUT);

END SP_EXPORT_IMAGE;


---------------- Export Blob File in physical directory. ------------------


DECLARE
V_BLOB BLOB;
 V_FILE_NAME VARCHAR2(300);
BEGIN
SELECT IMAGE_FRONT, DATA_NO INTO V_BLOB, V_FILE_NAME
FROM OUTWDCLR_REP
WHERE DATA_NO=77771613;

SP_EXPORT_IMAGE(V_BLOB,V_FILE_NAME||'.JPG','DATA_DIR');
END;

Tuesday, October 28, 2014

Replace character from Oracle Procedure, Function, Package and Trigger

You can replace character and compile Procedure, Function, Package and Trigger using this block.
----------------------------------------------------------------

DECLARE
  V_CLOB_USER CLOB;
  V_SEARCHING VARCHAR2(300):='FROM_USER';
  V_REPLACE_WITH VARCHAR2(300):='TO_USER';
 BEGIN
       
        FOR INDUSR IN (SELECT DISTINCT NAME, REPLACE (TYPE, 'PACKAGE BODY', 'PACKAGE') TYPE,U.OWNER OWNER_OBJECT
                          FROM DBA_SOURCE U, DBA_OBJECTS O
                         WHERE     O.OBJECT_NAME = U.NAME
                             AND U.OWNER = O.OWNER
                             AND U.OWNER = V_SEARCHING
                               AND TYPE IN ('PROCEDURE', 'FUNCTION', 'PACKAGES', 'TRIGGER', 'PACKAGE BODY')) LOOP

         BEGIN

         SELECT REPLACE(DBMS_METADATA.GET_DDL(INDUSR.TYPE,INDUSR.NAME,INDUSR.OWNER_OBJECT),V_SEARCHING,V_REPLACE_WITH) INTO V_CLOB_USER FROM DUAL;

         EXECUTE IMMEDIATE V_CLOB_USER;
           EXCEPTION
                    WHEN OTHERS THEN
                    DBMS_OUTPUT.PUT_LINE(SQLERRM);
          END;

   END LOOP;
END;

Wednesday, October 15, 2014

Send SMS using GSM Modem from Oracle Database

Send SMS using GSM Modem from Oracle Database

 SMSLib:

SMSLib provides a universal texting API, which can be used for sending and receiving messages via GSM modems.

Pre-requisites:

JDK 1.6 or higher
 JAVA Compiler

Configure SMSLib: You need the following files to configure SMSLib. You can find all of this file in Configuration_Files folder.

Download Files

Click the download link




1.       javax.comm.properties
2.       comm.jar
3.       RXTXcomm.jar
4.       win32com.dll
JAVA_HOME is path where jdk is installed

Step 1:- Copy comm.jar to
·         %JAVA_HOME%/lib  
[ In my case C:\Program Files\ Java\jdk1.7.0_03\lib ]
·         %JAVA_HOME%/jre/lib/ext
[ In my case C:\Program Files\ Java\jdk1.7.0_03\jre\lib\ext ]

Step 2:- Copy win32com.dll to
·         %JAVA_HOME%/bin
[In my case C:\Program Files\ Java\jdk1.7.0_03\bin ]
·         %JAVA_HOME%/jre/bin
      [ In my case C:\Program Files\ Java\jdk1.7.0_03\jre\bin ]
·         %windir%System32
             [ In my case C:\Windows\System32 ]

Step 3 : Copy javax.comm.properties to
·         %JAVA_HOME%/lib
            [ In my case C:\Program Files\ Java\jdk1.7.0_03\lib ]
·         %JAVA_HOME%/jre/lib
            [ In my case C:\Program Files\Java\jdk1.7.0_03\jre\lib ]
Step 4 : Copy RXTXcomm.jar to
·         %JAVA_HOME%/ jre/lib/ext
            [ In my case C:\Program Files\ Java\jdk1.7.0_03\lib ]

1.     Now open your NetBeans IDE

2.     You can find your modem port using CommunicationPortTest class. After finding port and bauds enter your port and bauds in SendSMS class. Please see red color line.

3.     Add the following jar files in your libraries (log4j-1.2.16.jar, ojdbc6.jar, smslib-3.5.1.jar)

4.     Create the following two class (SendSMS, DBCP)

5.     Create one table (SMS_LIST)

6.     Now insert row in SMS_LIST table and run project you can get SMS.

SendSMS Class


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smsgetway;
import org.smslib.AGateway;
import org.smslib.AGateway.GatewayStatuses;
import org.smslib.IOutboundMessageNotification;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
import java.sql.*;
/**
 *
 * @author rajib.pradhan
 */

public class SendSMS extends Thread {
    OutboundNotification outboundNotification;
    StringBuffer sql1;  
    SerialModemGateway gateway;
    String smsGatewayStatus = "";
    GatewayStatuses status;
    int i=0;
    public SendSMS() {
        try {
           
            outboundNotification = new OutboundNotification();
            SerialModemGateway gateway = new SerialModemGateway("modem.COM27", "COM27", 9600, "", "");
            gateway.setInbound(true);
            gateway.setOutbound(true);
            Service.getInstance().setOutboundMessageNotification(outboundNotification);
            Service.getInstance().addGateway(gateway);
            Service.getInstance().startService();
            status = gateway.getStatus();
            smsGatewayStatus = status.toString();
        } catch (Exception e) {
            System.out.println("EXCEPTION gateway.getStatus : "+gateway.getStatus());
            status = gateway.getStatus();
            smsGatewayStatus = status.toString();
            e.printStackTrace();
            System.out.println("Exception e.getMessage: " + e.getMessage());
            System.out.println("Exception cause: " + e.getCause());
        }
    }

    public void sendSMStoMobile() throws Exception {
        if (smsGatewayStatus.equals("STOPPED")) {
            return;
        }

        DBCP dbcp = DBCP.getInstance();
        Connection connection = dbcp.getConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = null;
       
        try {
            sql1 = new StringBuffer();
            sql1.append("SELECT MOBILE_NUMBER, MESSAGE, TRANUM ");
            sql1.append("FROM SMSGATEWAY.SMS_LIST ");
            sql1.append("WHERE SEND_STATUS = 'N' ");
            resultSet = statement.executeQuery(sql1.toString());
           
            while (resultSet.next()) {
              
                String destMobileNo = resultSet.getString(1);
                System.out.println("Phone Number "+resultSet.getString(1));
                String message = resultSet.getString(2);
                String tranNumber = resultSet.getString(3);
                OutboundMessage sms = new OutboundMessage(destMobileNo, message);
                Service.getInstance().sendMessage(sms);
                //Update Table After Send Message
                String updateQuery = "UPDATE SMSGATEWAY.SMS_LIST SET SEND_STATUS = 'Y' WHERE TRANUM = " + tranNumber ;
                if(i<20)
                {
               System.out.print(tranNumber+": Y, ");
               
                }
                if(i==20){
                System.out.print(tranNumber+": Y, "+"\n");
                i=0;
                }
                statement.executeUpdate(updateQuery);
                connection.commit();
                i=i+1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (resultSet != null) {
                resultSet.close();
            }
            if (statement != null) {
                statement.close();
            }
            dbcp.releaseConnection(connection);
        }
    }

    public class OutboundNotification implements IOutboundMessageNotification {

        public void process(AGateway gateway, OutboundMessage msg) {
            System.out.println(msg);
        }
    }

    public void run() {
        while (true) {
            try {
                sendSMStoMobile();
                this.sleep(1000);
            } catch (Exception e) {
            }
        }
    }

    public static void main(String[] args) throws Exception {
        SendSMS sendSMSFromDB = new SendSMS();
        sendSMSFromDB.start();
    }

    private void getModemInformation(SerialModemGateway gateway) throws Exception{
        System.out.println();
        System.out.println("Modem Information:");
       
        System.out.println("  Model: " + gateway.getModel());
        System.out.println("  Serial No: " + gateway.getSerialNo());
        System.out.println("  SIM IMSI: " + gateway.getImsi());
        System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
        System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
        System.out.println("  Manufacturer: " + gateway.getManufacturer());
        System.out.println();
    }
}

Database Connection (DBCP) Class


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smsgetway;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Vector;
import java.util.Stack;

/**
 *
 * @author rajib.pradhan
 */
/*
 *
 * Database Connection Information
 *
 */

public class DBCP implements Runnable {

    private static DBCP connectionPool;
    private Stack pool;
    private Vector busyConnections;
    private int MAX_CONNECTIONS = 10000;
    private int MIN_CONNECTIONS = 1;
    private long timeout;
    private String sDriver;
    private String sDBUrl;
    private String sUsername;
    private String sPassword;

    private DBCP(String sDriver,
                 String sUrl,
                 String sUserName,
                 String sPassword,
                 int sMaxConnection,
                 int sMinConnection,
                 long sTimeOut) throws SQLException {
       
        this.timeout = sTimeOut;
        this.sDriver = sDriver;
        this.sDBUrl = sUrl;
        this.sUsername = sUserName;
        this.sPassword = sPassword;
        this.MAX_CONNECTIONS = sMaxConnection;
        this.MIN_CONNECTIONS = sMinConnection;
        busyConnections = new Vector();
        pool = new Stack();
        for (int i = 0; i < MIN_CONNECTIONS; i++) {
            pool.push(makeNewConnection());
        }
    }

    public static DBCP getInstance() {
        if (connectionPool == null) {
            try {
                connectionPool =
                        new DBCP(
                        "oracle.jdbc.OracleDriver",
                       "jdbc:oracle:thin:@localhost:1521:ORCL",
                        "SMSGATEWAY",
                        "SMSGATEWAY",
                        10,
                        5,
                        30000);
            } catch (SQLException _sqlex) {
                _sqlex.printStackTrace();
            }
        }
        return connectionPool;
    }

    public synchronized Connection getConnection() throws SQLException, InterruptedException {
        Connection connection = null;
        if (connectionPool != null) {
            if (pool.size() != 0) {
                connection = (Connection) pool.pop();
                busyConnections.add(connection);
            } else {
                if (getTotalConnections() >= MAX_CONNECTIONS) {
                    while (busyConnections.size() < MAX_CONNECTIONS) {
                        connection = (Connection) pool.pop();
                        if (connection != null) {
                            connection.close();
                        }
                    }
                } else {
                    makeBackgroundConnection();
                    wait();
                    connection = getConnection();
                }
            }
        }
        return connection;
    }

    protected int getTotalConnections() {
        return pool.size() + busyConnections.size();
    }

    private void makeBackgroundConnection() throws SQLException {
        try {
            Thread connectionThread = new Thread(this);
            connectionThread.start();
        } catch (Exception _ex) {
            throw new SQLException("Max Limit of connections exceeded");
        }
    }

    private synchronized Connection makeNewConnection() throws SQLException {
        try {
            Class.forName(sDriver);
            Connection connection =
                    DriverManager.getConnection(sDBUrl, sUsername, sPassword);
            connection.setAutoCommit(false);
            return connection;
        } catch (ClassNotFoundException cnfe) {
            throw new SQLException("Can't find class for driver: " + sDriver);
        }
    }

    /**
     * run() function for making a new connection from the
     * backgroud called by makeBackgroundConnection()
     */
    public void run() {
        synchronized (this) {
            try {
                Connection con = makeNewConnection();
                pool.push(con);
                notifyAll();
            } catch (Exception _ex) {
            }
        }
    }

    /**
     *
     * @return Information about this connection pool
     */
    public synchronized void releaseConnection(Connection con) {
        pool.push(con);
        busyConnections.remove(con);
        notifyAll();
    }

    public synchronized String toString() {
        String info =
                "ConnectionPool("
                + sDBUrl
                + ","
                + sUsername
                + ")"
                + ", available="
                + pool.size()
                + ", busy="
                + busyConnections.size()
                + ", max="
                + MAX_CONNECTIONS;
        return info;
    }

    /**
     *
     * @throws SQLException
     */
    private synchronized void closeAllConnections() throws SQLException {
        while (!pool.isEmpty()) {
            try {
                ((Connection) pool.pop()).close();
            } catch (Exception _ex) {
                throw new SQLException("Unable to close the Connection");
            }
        }
        pool = new Stack();
        for (int i = 0; i < busyConnections.size(); i++) {
            try {
                ((Connection) busyConnections.get(i)).close();
                busyConnections.remove(i);
            } catch (Exception _ex) {
                throw new SQLException("Unable to close the Connection");
            }
        }
        busyConnections = new Vector();
    }

    /**
     *
     * @throws java.lang.Throwable
     */
    protected void finalize() throws java.lang.Throwable {
        try {
            closeAllConnections();
        } catch (Exception _ex) {
        }
        super.finalize();
    }
}

Port finding class (CommunicationPortTest.class)

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smsgetway;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Formatter;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import org.smslib.helper.CommPortIdentifier;
import org.smslib.helper.SerialPort;

/**
 *
 * @author rajib.pradhan
 */

public class CommunicationPortTest {

    private static final String _NO_DEVICE_FOUND = "No Device Found.";
    private final static Formatter _formatter = new Formatter(System.out);
    static CommPortIdentifier portId;
    static Enumeration<CommPortIdentifier> portList;
    static int bauds[] = {9600, 14400, 19200, 28800, 33600, 38400, 56000, 57600, 115200};

    /**
     * Wrapper around {@link CommPortIdentifier#getPortIdentifiers()} to be
     * avoid unchecked warnings.
     */
    private static Enumeration<CommPortIdentifier> getCleanPortIdentifiers() {
        return CommPortIdentifier.getPortIdentifiers();
    }

    public static void main(String[] args) {
        System.out.println("\nSearching for devices...");
        portList = getCleanPortIdentifiers();
        while (portList.hasMoreElements()) {
            portId = portList.nextElement();
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                _formatter.format("%nFound port: %-5s%n", portId.getName());
                for (int i = 0; i < bauds.length; i++) {
                    SerialPort serialPort = null;
                    _formatter.format("       Trying at %6d...", bauds[i]);
                    try {
                        InputStream inStream;
                        OutputStream outStream;
                        int c;
                        String response;
                        //serialPort = portId.open("SMSLibCommTester", 1971);
                        serialPort = portId.open("SMSAPP", 1971);
                        serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN);
                        serialPort.setSerialPortParams(bauds[i], SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                        inStream = serialPort.getInputStream();
                        outStream = serialPort.getOutputStream();
                        serialPort.enableReceiveTimeout(1000);
                        c = inStream.read();
                        while (c != -1) {
                            c = inStream.read();
                        }
                        outStream.write('A');
                        outStream.write('T');
                        outStream.write('\r');
                        Thread.sleep(1000);
                        response = "";
                        StringBuilder sb = new StringBuilder();
                        c = inStream.read();
                        while (c != -1) {
                            sb.append((char) c);
                            c = inStream.read();
                        }
                        response = sb.toString();
                        if (response.indexOf("OK") >= 0) {
                            try {
                                System.out.print("  Getting Info...");
                                outStream.write('A');
                                outStream.write('T');
                                outStream.write('+');
                                outStream.write('C');
                                outStream.write('G');
                                outStream.write('M');
                                outStream.write('M');
                                outStream.write('\r');
                                response = "";
                                c = inStream.read();
                                while (c != -1) {
                                    response += (char) c;
                                    c = inStream.read();
                                }
                                System.out.println(" Found: " + response.replaceAll("\\s+OK\\s+", "").replaceAll("\n", "").replaceAll("\r", ""));
//                                JOptionPane.showMessageDialog(null," Found: " + response.replaceAll("\\s+OK\\s+", "").replaceAll("\n", "").replaceAll("\r", ""), "Warning",
//                                JOptionPane.WARNING_MESSAGE);
                            } catch (Exception e) {
                                System.out.println(_NO_DEVICE_FOUND);
//                                JOptionPane.showMessageDialog(null, _NO_DEVICE_FOUND, "Warning",
//                                JOptionPane.WARNING_MESSAGE);
                            }
                        } else {
                            System.out.println(_NO_DEVICE_FOUND);
//                            JOptionPane.showMessageDialog(null, _NO_DEVICE_FOUND, "Warning",
//                                JOptionPane.WARNING_MESSAGE);
                        }
                    } catch (Exception e) {
                        System.out.print(_NO_DEVICE_FOUND);
//                        JOptionPane.showMessageDialog(null, _NO_DEVICE_FOUND, "Warning",
//                                JOptionPane.WARNING_MESSAGE);
                        Throwable cause = e;
                        while (cause.getCause() != null) {
                            cause = cause.getCause();
                        }
                        System.out.println(" (" + cause.getMessage() + ")");
                    } finally {
                        if (serialPort != null) {
                            serialPort.close();
                        }
                    }
                }
            }
        }
        System.out.println("\nCommunication Test Completed.");
//        JOptionPane.showMessageDialog(null, "Communication Test Completed.", "Information",
//                                JOptionPane.INFORMATION_MESSAGE);
    }
}

Table Scripts

CREATE TABLE SMS_LIST
(
  MOBILE_NUMBER  VARCHAR2(20 BYTE),
  MESSAGE        VARCHAR2(300 BYTE),
  SEND_STATUS    CHAR(1 BYTE)                   DEFAULT 'N',
  TRANUM         VARCHAR2(30 BYTE)
)