Showing posts with label ORACLE 12C. Show all posts
Showing posts with label ORACLE 12C. Show all posts

Wednesday, 2 July 2014

Oracle 12C new featureTemporal Virtual Columns start date and end date for Dimension tables


Oracle 12C new featureTemporal  Virtual Columns start date and end date for Dimension tables
    Valid time temporal support is typically used with Oracle Flashback technology, to perform AS OF and VERSIONS BETWEEN queries that specify the valid time period. You can also use the DBMS_FLASHBACK_ARCHIVE.enable_at_valid_time procedure to specify a option for the visibility of table data: all table data (the default), valid data as of a specified time, or currently valid data within the valid time period at the session level.

    Some scenarios where valid time temporal support can be useful include:
    • Information Lifecycle Management (ILM) and any other application where it is important to know when certain data became valid (from the application's perspective) and when it became invalid (if it ever did)
    • Data correction where incorrect data needs to be retained and marked with the period when it was considered valid, and where the correct data needs to be visible as currently valid

Example:
------------
Creating one dim table 

CREATE TABLE hr.emp_dim AS
SELECT employee_id, first_name, salary FROM hr.employees;

Adding Valid_time into new dim table:

ALTER TABLE emp_dim ADD period FOR valid_time;

if you see desc emp_dim
we can see only three columns employee_id,first_name,salary
we can't see  valid_time_start and valid_time_end hidden columns.

If we want to see the hidden columns we need to include in SQL select query.

select first_name,
to_char(valid_time_start,'dd-mon-yyyy') "Start",
to_char(valid_time_end,'dd-mon-yyyy') "End"
from hr.emp_dim;


We can insert start date and end date values using below queries.

UPDATE emp_dim
SET valid_time_start = to_date('01-JUN-1995','dd-MON-yyyy'),
  valid_time_end     = to_date('15-SEP-2010','dd-MON-yyyy')
WHERE first_name    IN ('Lex','Alexander','Bruce','David','Daniel');

UPDATE emp_dim
SET valid_time_start = to_date('01-AUG-1999','dd-MON-yyyy'),
  valid_time_end     = to_date('01-MAR-2012','dd-MON-yyyy')
WHERE first_name    IN ('Steven','Diana');

UPDATE emp_dim
SET valid_time_start = to_date('20-MAY-1998','dd-MON-yyyy')
WHERE first_name    IN ('Neena','Nancy','Valli');


COMMIT;














Tuesday, 1 July 2014

Oracle Database 12c New Features for Developers

Oracle Database 12c New Features for Developers

Session level sequences
A new SESSION level database sequence can be created now in 12c to support the session level sequence values. These types of sequences are most useful and suitable on global temporary tables that have session level existence.

Session level sequences produce a unique range of values that are limited within the session, not across the sessions. Once the session ends, the state of the session sequences also goes away. The following example explains creating a session level sequence:
Examples:
SQL> CREATE SEQUENCE my_seq START WITH 1 INCREMENT BY 1 SESSION;

SQL> ALTER SEQUENCE my_seq GLOBAL|SESSION;

While Creating Table we can use Sequence as Default Value
With Oracle Database 12c, we can directly assign sequence nextval as a default value for a column, So you no longer need to create a trigger to populate the column with the next value of sequence, you just need to declare it with table definition.

Example:
create sequence product_seqno start with 1 increment by 1 nocycle;

create table product_dim
(
   product_id number default product_seqno.nextval,
  product_name     varchar2(30),
  qty                      number,
  status                  varchar2(1),
  cre_date             date,
);


Table Level Invisible column:
Oracle Database 12c provides you the Invisible column feature. A Column defined as invisible, will not appear in generic queries (select * from). An Invisible Column need to be explicitly referred to in the SQL statement or condition. Also invisible column must be explicitly referred in INSERT statement to insert the database into invisible columns.

Example:
SQL> create table emp
   (
   emp id number,
    ename varchar2(100),
    email varchar2(100),
    sal number,    
    comm number INVISIBLE,
    deptno number
    );
  
SQL> ALTER TABLE my_table MODIFY (password visible);  


Multiple indexes on the same column
Before Oracle Database 12c, we could not have multiple indexes on a single column. In Oracle Database 12c a column may have multiple indexes but all should be of different types. Like a column may have B-Tree and BitMap Index both. But, only one index will be used at a given time.


VARCHAR2 length up to 32767  (Not Verified in 12.1.0 version)
Form Oracle Database 12c, a varchar2 column can be sized upto 32767, which was earlier 4000. The maximum size of the VARCHAR2, NVARCHAR2, and RAW data types has been increased from 4,000 to 32,767 bytes.


Analytical  Functions same as MYSQL  Top-N feature
A Top-N query is used to retrieve the top or bottom N rows from an ordered set. Combining two Top-N queries gives you the ability to page through an ordered set
Example:
SQL> SELECT sal
    FROM   emp
    ORDER BY sal DESC
    FETCH FIRST 10 ROWS ONLY;


Sequence Values generating using  IDENTITY Columns
In Oracle Database 12c, We can define Table columns with SQL keyword IDENTITY which is a American National Standards Institute (ANSI) SQL keyword. Which are auto-incremented at the time of insertion (like in MySQL).
Example:
SQL> create table EMP
    (
    empid number generated as identity,
    ename varchar2(100),
    email varchar2(100),
    sal  number,
    comm number,
   deptno number  
    );


PLSQL Function with  WITH Clause improvement
In Oracle 12c, we can declare PL/SQL functions in the WITH Clause of a select statement and use it as an ordinary function. Using this construct results in better performance as compared with schema-level functions
Example:
SQL> WITH
     FUNCTION emp_f(n IN NUMBER) RETURN NUMBER IS
     BEGIN
        RETURN n+1;
      END;
    SELECT  EMP_F(1)
    FROM   dual ;


Cascade for TRUNCATE and EXCHANGE partition.

With Oracle Database 12c, The TRUNCATE can be executed with CASCADE option which will also delete the child records.
Example:
SQL>  TRUNCATE TABLE EMP  CASCADE;

Move table partition to different Tablespace online

From Oracle 12c, it become very easy to move Table Partition to different tablespace and does not require complex steps
Example:
  SQL> ALTER TABLE MY_LARGE_TABLE MOVE PARTITION MY_LARGE_TABLE_PART1 TO TABLESPACE USERS_NEW;



Temporary Undo
Before Oracle Database 12c, undo records of temporary tables used to be stored in undo tablespace. With the temporary undo feature in Oracle Database 12c, the undo records of temporary tables can now be stored in a temporary table instead of stored in undo tablespace. The main benefits of temporary undo are 1) Low undo tablespace usages 2) less redo data generation. For using this feature Compatibility parameter must be set to 12.0.0 or higher and TEMP_UNDO_ENABLED initialization parameter must be Enabled.


DDL logging
By using the ENABLE_DDL_LOGGING initiation parameter in Oracle Database 12c, we can now log the DDL action into xml and log files to capture when the drop or create command was executed and by whom under the $ORACLE_BASE/diag/rdbms/DBNAME/log|ddl location. The parameter can be set at the database or session levels.
Example:
  SQL> ALTER SYSTEM SET ENABLE_DDL_LOGGING=TRUE;


Saturday, 28 June 2014

Oracle 12c New feature to get USER ID ORA_INVOKING_USERID

Oracle 12c New feature to get USER ID ORA_INVOKING_USERID


Returns the user id of the database user who invoked the current statement or view

Example:  (ORA_INVOKING_USER RETURN NUMBER)


SELECT ora_invoking_userid  FROM dual;

Oracle 12c New feature to get USER ORA_INVOKING_USER

Oracle 12c New feature to get USER ORA_INVOKING_USER
 

Returns the name of the database user who invoked the current statement or view

Example: (ORA_INVOKING_USER RETURN VARCHAR2)

SELECT ora_invoking_user  FROM dual;

Oracle 12c Greatest feature for developers can use Default value as sequences.

Oracle 12c Greatest feature for developers can use Default value as sequences while creating a table.

Default value can reference sequences
This is also for developers who struggle to maintain unique values in
Primary Key columns. While creating a table default column can be
referenced by sequence.nextval.

This feature is required for every developer while creating table we can declare default 
sequence name for PK column in place manual using in insert script.



Oracle 12c New Features Duplicate Indexes on the same set of columns

Duplicate Indexes  

Create duplicate indexes on the same set of columns. Like in large
applications you might want two different types of index on the same data.


Oracle 12C New features Analytical Function Improvements same as MYSQL.

Analytical Function Improvements same as MYSQL.

Top-N feature
As like MySQL(limit clause), Oracle 12c will allow Top-N feature in
queries. Analytical function improvements.

Examples:

SELECT EMPNO,ENAME,DEPTNO FROM EMP ORDER BY SAL
FETCH FIRST 5 ROWS ONLY;




Oracle Database 12c Supporting VARCHAR2 length up to 32767.


VARCHAR2 length up to 32767

This one will be one of the best feature for developers who always struggle
to manage large chunk of data. Current version of databases allows only
up to 4000 bytes in a single varchar2 cell. So developers has to either use
CLOB or XML data types which are comparatively slower that varchar2
processing.