Thursday, April 30, 2015

Creating Efficient Temporary Views

Some times you need a table or a view of data that does not exist to construct a needed query and do not have the authority to create such a table or view on your database.








At times, within a single SQL statement, you want to create a table “on the fly” that is used solely for your query and will never be used again. In the FROM clause of your query, you normally place the name of your table or view on which to retrieve the data. In cases where a needed view of the data does not exist, you can create a temporary view of that data with what is called an “inline view,” where you specify the characteristics of that view right in the FROM clause of your query:


SELECT last_name, first_name, department_name dept, salary
FROM employees e join
( SELECT department_id, max(salary) high_sal
FROM employees
GROUP BY department_id ) m
USING (department_id) join departments
USING (department_id)
WHERE e.salary = m.high_sal
ORDER BY SALARY desc;

Full Database Caching Mode

Enable Force Full Database Caching Mode
 
[oracle@localhost~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu Jul 31 05:09:01 2014
Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> select force_full_db_caching from v$database;
FOR

NO


SQL> alter database force full database caching;
alter database force full database caching
*
ERROR at line 1:
ORA-01126: database must be mounted in this instance and not open in any
instance


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 1644167168 bytes
Fixed Size                  2925024 bytes
Variable Size            1375735328 bytes
Database Buffers          251658240 bytes
Redo Buffers               13848576 bytes
Database mounted.
SQL> alter database force full database caching;

Database altered.
SQL> alter database open;
Database altered.
SQL> select force_full_db_caching from v$database;
FOR

YES

 
Disable Force Full Database Caching Mode
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 1644167168 bytes
Fixed Size                  2925024 bytes
Variable Size            1375735328 bytes
Database Buffers          251658240 bytes
Redo Buffers               13848576 bytes
Database mounted.
SQL> alter database no force full database caching;

Database altered.
SQL> alter database open;
Database altered.
SQL> select force_full_db_caching from v$database;
FOR

NO

Wednesday, April 29, 2015

Database Upgrade from 12.1.0.1 to 12.1.0.2