VARCHAR2, NVARCHAR2,
and RAW
data types has been increased from 4,000 to 32,767 bytes.Increasing the allotted size for these data types allows users to store more information in character data types before switching to large objects (LOBs). This is especially useful for brief textual data types and the capabilities to build indexes on these types of columns.
2. DEFAULT Values for Columns on Explicit NULL Insertion
The
DEFAULT
definition of a column can be extended to have the DEFAULT
being applied for explicit NULL
insertion.
The
DEFAULT
clause has a new ON NULL
clause, which instructs the database to assign a specified default column value when an INSERT
statement attempts to assign a value that evaluates to NULL
.
Ex:
create table default_on_null (id number, name varchar2(4000) default on null 'Anand' ,name2 varchar2(4000) default 'Yadav');
insert into default_on_null values(1,null,null);
select * from default_on_null;
1 Anand
It returns default value of name field in place of null. It makes sure that there will never be null value in name field.
3. Identity Columns
Ex: No more sequences needs to be defined and use identity_clause that is almost identical to sequence
CREATE TABLE t7 (c1 NUMBER GENERATED ALWAYS AS IDENTITY (start with 1 increment by 1 cache 50 nocycle) ,
c2 VARCHAR2(10));
INSERT INTO t7(c2) VALUES ('’abc');
INSERT INTO t7 (c1, c2) VALUES (null, '’xyz');--It will fail as ALWAYS mentioned so you cannot insert or update this column value
If you want to insert user defined value as well then write it like this.
CREATE TABLE t8 (c1 NUMBER GENERATED AS IDENTITY (start with 1 increment by 1 cache 50 nocycle) ,
c2 VARCHAR2(10));
SELECT c1, c2 FROM t7;
UPDATE t7 SET C1=3 WHERE C1=1
Ex: Use of always so that user don't have to insert/update any value
CREATE TABLE t6 (c1 NUMBER GENERATED ALWAYS AS IDENTITY ,
c2 VARCHAR2(10));
INSERT INTO t6(c2) VALUES ('’abc');
INSERT INTO t6 (c1, c2) VALUES (null, '’xyz');--It will fail
SELECT c1, c2 FROM t6;
UPDATE T6 SET C1=3 WHERE C1=1--It will fail
Ex: Default sequence will be used but user can insert/update values
CREATE TABLE t5 (c1 NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY,
c2 VARCHAR2(10));
INSERT INTO t5(c2) VALUES ('’abc');
INSERT INTO t5 (c1, c2) VALUES (null, '’xyz');
SELECT c1, c2 FROM t5;
3. Identity Columns
Oracle Database 12c Release 1 implements ANSI-compliant
This feature implements auto increment by enhancing IDENTITY
columns. Migration from database systems that use identity columns is simplified and can take advantage of this new functionality.DEFAULT
or DEFAULT ON NULL
semantics for use by SEQUENCE.NEXTVAL
and SYS_GUID
, supports built-in functions and implicit return of default values.Ex: No more sequences needs to be defined and use identity_clause that is almost identical to sequence
CREATE TABLE t7 (c1 NUMBER GENERATED ALWAYS AS IDENTITY (start with 1 increment by 1 cache 50 nocycle) ,
c2 VARCHAR2(10));
INSERT INTO t7(c2) VALUES ('’abc');
INSERT INTO t7 (c1, c2) VALUES (null, '’xyz');--It will fail as ALWAYS mentioned so you cannot insert or update this column value
If you want to insert user defined value as well then write it like this.
CREATE TABLE t8 (c1 NUMBER GENERATED AS IDENTITY (start with 1 increment by 1 cache 50 nocycle) ,
c2 VARCHAR2(10));
SELECT c1, c2 FROM t7;
UPDATE t7 SET C1=3 WHERE C1=1
Ex: Use of always so that user don't have to insert/update any value
CREATE TABLE t6 (c1 NUMBER GENERATED ALWAYS AS IDENTITY ,
c2 VARCHAR2(10));
INSERT INTO t6(c2) VALUES ('’abc');
INSERT INTO t6 (c1, c2) VALUES (null, '’xyz');--It will fail
SELECT c1, c2 FROM t6;
UPDATE T6 SET C1=3 WHERE C1=1--It will fail
Ex: Default sequence will be used but user can insert/update values
CREATE TABLE t5 (c1 NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY,
c2 VARCHAR2(10));
INSERT INTO t5(c2) VALUES ('’abc');
INSERT INTO t5 (c1, c2) VALUES (null, '’xyz');
SELECT c1, c2 FROM t5;
4. Top N queries simplified in 12C
Ex: First 10 rows or first 10 percent rows
SELECT T.*
FROM T
ORDER BY OWNER,OBJECT_NAME
FETCH first 10 <percent> ROWS ONLY
Ex: Rows from 6th to 16th
SELECT T.*
FROM T
ORDER BY OWNER,OBJECT_NAME
OFFSET 5 ROWS
FETCH NEXT 10 ROWS ONLY;
Internally oracle usage analytical functions only to get these records but user don't need to know all that. You may check predicates in explain plan to verify how query actually executed.
Ex: First 10 rows or first 10 percent rows
SELECT T.*
FROM T
ORDER BY OWNER,OBJECT_NAME
FETCH first 10 <percent> ROWS ONLY
Ex: Rows from 6th to 16th
SELECT T.*
FROM T
ORDER BY OWNER,OBJECT_NAME
OFFSET 5 ROWS
FETCH NEXT 10 ROWS ONLY;
Internally oracle usage analytical functions only to get these records but user don't need to know all that. You may check predicates in explain plan to verify how query actually executed.
No comments:
Post a Comment