1. OCA/OCP Oracle Database 11g All-in-One Exam Guide with CD-ROM by John Watson.
2. Oracle PL/SQL Programming by Steven Feuerstein
Another DBA blog in the blogosphere. Odds and sods about Oracle administration.
select o.owner, o.object_type, o.object_name, t.column_name, co.search_condition, co.validated from dba_objects o, sys.col$ c, dba_tab_columns t, dba_cons_columns cc, dba_constraints co where o.owner = '&table_owner' and o.object_type = 'TABLE' and o.object_id = c.obj# and o.owner = t.owner and o.object_name = t.table_name and t.column_name = c.name and cc.owner = o.owner and cc.table_name = t.table_name and cc.column_name = c.name and co.owner = cc.owner and co.constraint_name = cc.constraint_name and co.constraint_type = 'C' and c.null$ = 0 order by object_name, column_name;Note that in 10g and 11g the DBA_CONSTRAINTS.SEARCH_CONDITION column is stored as a LONG. Which means that you can't filter out NOT NULL check conditions (e.g. "column_name in (0,1)") from any other check conditions in the query.
select o.owner, o.object_type, o.object_name, t.column_name, co.search_condition, co.validated from dba_objects o, sys.col$ c, dba_tab_columns t, dba_cons_columns cc, my_dba_constraints co where o.owner = '&table_owner' and o.object_type = 'TABLE' and o.object_id = c.obj# and o.owner = t.owner and o.object_name = t.table_name and t.column_name = c.name and cc.owner = o.owner and cc.table_name = t.table_name and cc.column_name = c.name and co.owner = cc.owner and co.constraint_name = cc.constraint_name and co.constraint_type = 'C' and c.null$ = 0 and co.search_condition not like '% AND %' and co.search_condition not like '% OR %' and co.search_condition like '%NOT NULL%' order by object_name, column_name;
set serveroutput on size unlimited DECLARE jswap NUMBER ; jint NUMBER := 17 ; lcount NUMBER := 0 ; lrowcount NUMBER := 0 ; TYPE tab_ba IS TABLE OF client_bank_accts%ROWTYPE INDEX BY BINARY_INTEGER; array_ba tab_ba ; CURSOR r IS SELECT * FROM client_bank_accts; sav_banksortcd client_bank_accts.banksortcd%TYPE; sav_bankacctnbr client_bank_accts.bankacctnbr%TYPE; BEGIN OPEN r; LOOP FETCH r BULK COLLECT INTO array_ba LIMIT 5000; lrowcount := array_ba.COUNT; FOR i IN REVERSE 1 .. array_ba.COUNT LOOP jswap := trunc(dbms_random.value(1, i+1)); sav_banksortcd := array_ba(i).banksortcd; sav_bankacctnbr := array_ba(i).bankacctnbr; UPDATE client_bank_accts SET banksortcd = array_ba(jswap).banksortcd, bankacctnbr = array_ba(jswap).bankacctnbr WHERE clientbankacctseq = array_ba(i).clientbankacctseq; UPDATE client_bank_accts SET banksortcd = sav_banksortcd, bankacctnbr = sav_bankacctnbr WHERE clientbankacctseq = array_ba(jswap).clientbankacctseq; lcount := lcount + 2; END LOOP; EXIT WHEN r%NOTFOUND; COMMIT; END LOOP; CLOSE r; dbms_output.put_line('Completed. '||to_char(lcount)||' rows updated!'); END; /
#!/bin/bashIn our crontab file we have two entries for our backup, as follows:
[ $(cal | awk '{print $1}' | tr -s '[:blank:]' '\n' | tail -1) = $(date +%d) ]
# Check if day is LAST SUNDAY of Month. If NOT, run the regular backupBoth schedules run at the same time, but only one of them will actually execute, depending upon the day of the month. The actual backup commands are bracketed, so that they are ALL dependent upon the islastsunday script, and will all run with the same retention policy, even if the backups continue to run after midnight (i.e. in Monday!).
30 00 * * * islastsunday || (rman-job.sh level_0_tape ORCL > level_0_tape_ORCL.log 2>&1; rman-job.sh level_0_tape ORCL2 > level_0_tape_ORCL2.log 2>&1)
# Check if day is LAST SUNDAY of Month. If it IS, run the Monthly backup
30 00 * * * islastsunday && (rman-job.sh level_0_tape_LS ORCL > level_0_tape_LS_ORCL.log 2>&1; rman-job.sh level_0_tape_LS ORCL2 > level_0_tape_LS_ORCL2.log 2>&1)
backup device type disk database plus archivelog include current controlfile;The backup worked fine. So we logged on to the new server, made sure that we could see the NFS-mounted FRA, and issued the Duplicate command.
run {Oddly, it didn't work. It returned an error saying that a backup could not be found.
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
allocate auxiliary channel da1 type disk;
allocate auxiliary channel da2 type disk;
allocate auxiliary channel da3 type disk;
allocate auxiliary channel da4 type disk;
duplicate target database to CATDB;
}
Starting restore at 20-MAY-11If we tried using automatic channel allocations for the restore, it still did not find our disk backup, but tried restoring older tape backups. Not what we wanted.
released channel: da1
released channel: da2
released channel: da3
released channel: da4
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 20/05/2011 15:25:38
RMAN-03015: error occurred in stored script Memory Script
RMAN-06026: some targets not found - aborting restore
RMAN-06100: no channel to restore a backup or copy of datafile 1
RMAN-06100: no channel to restore a backup or copy of datafile 2
etc...
SQL> create table poo (x date);
Table created.
SQL> create index poodex on poo(x);
Index created.
SQL> select object_name,
to_char(last_ddl_time, 'DD-Mon-YYYY HH24:MI:ss')
2 from dba_objects where object_name like 'POO%';
OBJECT_NAME TO_CHAR(LAST_DDL_TIM
----------- --------------------
POO 22-Mar-2011 10:09:51
POODEX 22-Mar-2011 10:09:51
SQL> alter index poodex rebuild online;
Index altered.
SQL> select object_name,
to_char(last_ddl_time, 'DD-Mon-YYYY HH24:MI:ss')
2 from dba_objects where object_name like 'POO%';
OBJECT_NAME TO_CHAR(LAST_DDL_TIM
----------- --------------------
POO 22-Mar-2011 10:11:31
POODEX 22-Mar-2011 10:11:31
14:16:55 PETE @ ETEST1D > create table foo (foocol number(5));
Table created.
14:17:20 PETE @ ETEST1D > @lastddl
OBJECT_NAME TO_CHAR(LAST_DDL_TIME,'DD-MON-
------------------------------ ------------------------------
FOO 28-Mar-2011 14:17:20
14:18:35 PETE @ ETEST1D > create procedure fooproc is
14:19:13 2 v_var varchar2(10);
14:19:26 3 begin
14:19:31 4 null;
14:19:38 5 exception
14:19:42 6 when others then null;
14:19:45 7 end;
14:19:47 8 /
Procedure created.
14:19:50 PETE @ ETEST1D > @lastddl
OBJECT_NAME TO_CHAR(LAST_DDL_TIME,'DD-MON-
------------------------------ ------------------------------
FOO 28-Mar-2011 14:17:20
FOOPROC 28-Mar-2011 14:19:50
14:20:06 PETE @ ETEST1D > create or replace procedure fooproc is
14:20:31 2 v_var varchar2(10);
14:20:34 3 begin
14:20:36 4 select to_char(foocol)
14:21:02 5 into v_var
14:21:07 6 from foo;
14:21:14 7 exception
14:21:17 8 when others then null;
14:21:18 9 end;
14:21:19 10 /
Procedure created.
14:21:20 PETE @ ETEST1D > @lastddl
OBJECT_NAME TO_CHAR(LAST_DDL_TIME,'DD-MON-
------------------------------ ------------------------------
FOO 28-Mar-2011 14:17:20
FOOPROC 28-Mar-2011 14:21:20
14:21:31 PETE @ ETEST1D > alter procedure fooproc compile;
Procedure altered.
14:22:07 PETE @ ETEST1D > @lastddl
OBJECT_NAME TO_CHAR(LAST_DDL_TIME,'DD-MON-
------------------------------ ------------------------------
FOO 28-Mar-2011 14:17:20
FOOPROC 28-Mar-2011 14:22:07
14:22:13 PETE @ ETEST1D > drop procedure fooproc;
Procedure dropped.
14:22:40 PETE @ ETEST1D > @lastddl
OBJECT_NAME TO_CHAR(LAST_DDL_TIME,'DD-MON-
------------------------------ ------------------------------
FOO 28-Mar-2011 14:17:20
14:24:20 PETE @ ETEST1D > comment on table foo is 'FOO is a test table';
Comment created.
14:24:25 PETE @ ETEST1D > @lastddl
OBJECT_NAME TO_CHAR(LAST_DDL_TIME,'DD-MON-
------------------------------ ------------------------------
FOO 28-Mar-2011 14:24:25
select sum(
ora_hash(COLUMN_NAME||
DATA_TYPE||
to_char(NVL(DATA_LENGTH,0))||
to_char(NVL(DATA_SCALE,0))||
to_char(NVL(DATA_PRECISION,0))
)
) t_hash
from all_tab_columns
where table_name = '&table_name'
and owner = '&owner';
t_signatureThis signature is unique to the table structure. It returns a different value if a column is added or dropped, or if its datatype, size or scale changes.
----------------------
141887801613