In this post, I’d like to introduce 5 of the many new features Oracle 12C brings to us, database developer’s.
Of course this blog would be to long to explain them all in detail, so I will stick
to a small introduction.
- Generating a primary key without triggers, using nextval or identity
In 12C, you are now able to use sequence.nextval or the new keyword ‘identity’ as default values.
The ‘identity’ keyword will generate the value max(id)+1 for your primary key. So now you don’t need to create triggers anymore, when generating PK’s with a sequence.
And problems with sequences that are not in sync, when moving/copying tables to another schema/database, can be avoided by using the ‘identity’ keyword.
Example PK row declaration :
id_pers number default person_seq.nextval primary key;
id_pers number generated as identity;
- Accessible key word : define which code can call your function/procedure.
One of the major problems of PL/SQL is, when developing a lot of packages/procedures/functions, in the end there is no telling who is called by who. This problem can now be answered by ‘white listing’. This means that, on creation, you are telling the package/function/procedure/type by whom it is accessible, or may be used.
The accessible by clause takes packages/functions/procedures/triggers as accessor clause.
Example white listing :
– create procedure get_sales_data accessible by (my_sales_proc)…
– create procedure get_sales_data accessible by (my_after_update_trigger)
– create package my_package accessible by (my_other_package)…When the object is not accessible, following error will be thrown during compilation, or at runtime, in case of an anonymous PL/SQL block :PLS-00904: insufficient privilege to access object MY_PACKAGE.MY_PROCEDURE
- Temporal Validity of a row
Sometimes rows in a table are valid or not, depending on a timeframe. For instance a subscription for a magazine, may only be valid for a year. Adding this validity to a row goes as follows :
create table subscriptions ( person_id number, subscription_id number, person_name varchar2(500), subscr_start_date date, subscr_end_date date, period for valid(subscr_start_date , subscr_end_date) )
Now with following query we can select the ‘valid’ subscriptions :
select * from subscriptions as of period for valid sysdate;
- New PL/SQL Package UTL_CALL_STACK
The UTL_CALL_STACK package provides subprograms to return the current call stack for a PL/SQL program. This could already be done by DBMS_UTILITY.FORMAT_CALL_STACK, but this new package returns this information in a more structured way, and includes the depth of the call (calling level) and the names of the subprograms.
This will make this information more usable in code. Related to this subject, 2 new directives are added in 12c, next to $$PLSQL_LINE and $$PLSQL_UNIT that already existed).
dbms_output_put.line("Owner of this package is "+$$PLSQL_OWNER);
Will print : Owner of this package is SCOTT
- An Invoker’s Rights Function Can Be Result Cached
Caching results of a PL/SQL function already exists in 11g. Basically what happens is that, for a certain function, you define that the result, for given parameters should be cached in memory.
So first time function getPerson(123) is executed, the data is fetched from the database, second time the function is called with parameter ‘123’, the result is fetched from the cache in memory, resulting in a better performance.
Whenever a DML statement is executed on the table(s) used in that function, the cache is automatically cleared, causing the next call to return the new data. (Since 11G rel. 2, Oracle manages these dependencies himself.)
So in our case, Oracle caches the result’s of function getPerson() for every key it is called with.
Through Oracle Database 11g Release 2 (11.2), only definer’s rights PL/SQL functions could be result cached. Now in 12c, the identity of the invoker is implicitly added to that key.
As already mentioned, the possibilities of these new features go way beyond what I describe here. But hopefully it’s a start to a few experiments on your side !
More info can be found at http://docs.oracle.com/cd/E16655_01/server.121/e17906/chapter1.htm