By Laurent Schneider
It is a very common task for a DBA to be asked to create scripts
that work on every version. But how do you return NULL if a column
does not exist? Imagine I have a view that returns the
table_name, column_name and retention_type of my LOBS as follows:
SQL> create table
t1(c clob) lob(c) store as (retention);
Table created.
SQL> create table t2(c clob) lob(c) store as (pctversion 10);
Table created.
SQL> create or replace force view v as select table_name,
column_name,retention_type from user_lobs;
View created.
SQL> select * from v where table_name in ('T1','T2');
TAB COL RETENTION_TYPE
--- --- --------------
T1 C YES
T2 C NO
Now try running this on an "antique" version of Oracle:
SQL> select version from v$instance;
VERSION
-----------------
11.2.0.1.0
SQL> create table t1(c clob) lob(c) store as (retention);
Table created.
SQL> create table t2(c clob) lob(c) store as (pctversion 10);
Table created.
SQL> create or replace force view v as select
table_name,column_name,retention_type from user_lobs;
Warning: View created with compilation errors.
SQL> select * from v where table_name in ('T1','T2');
select * from v where table_name in ('T1','T2')
*
ERROR at line 1:
ORA-04063: view "SCOTT.V" has errors
Obviously the RETENTION_TYPE did not exist in that version. Let�s
default this to NULL !
SQL> create
or replace function retention_type return varchar2 is
begin return null; end;
/
Function created.
SQL> select * from v where table_name in ('T1','T2');
TAB COL RETENTION_TYPE
--- --- --------------
T1 C
T2 C
It really is a surprisingly simple workaround, isn't it?
|
|
|
Get the Complete
Oracle Tuning Details
The landmark book
"Oracle
Tuning: The Definitive Reference Second Edition" has been
updated with over 1,150 pages of expert performance tuning tips.
It's packed with scripts and tools to hypercharge Oracle 11g
performance and you can
buy it for 40% off directly from the publisher.
|
|
Download your Oracle scripts now:
www.oracle-script.com
The
definitive Oracle Script collection for every Oracle professional DBA
|
|
|
|

Copyright ©
1996 -2017 by Burleson. All rights reserved.
Oracle® is the registered trademark of Oracle
Corporation. SQL Server® is the registered trademark of Microsoft
Corporation. Many of the designations used by computer vendors to distinguish their
products are claimed as Trademarks
|
|