ieee day 2013 oracle database 12c: new features for developers
DESCRIPTION
IEEE Day 2013 Baku Oracle Database 12c: new features PL/SQL and Java developers.TRANSCRIPT
IEEE Day 2013
Ramin OrujovICT/Internal Applications Team HeadAzercell TelecomSCJP 6, OCE Java EE 6 WCD
www.linkedin.com/in/raminorujov
01 October 2013, Qafqaz University
Oracle database 12c: New features for developers
About me
Senior software developer
Internal Applications Team Head@Azercell
Teacher @ Qafqaz University CE dept.
Co-manager of AZEROUG
Founder and manager of AZERJUG
April 9, 20232
Oracle database platforms
Oracle 9i – internetOracle 10g/11g – gridOracle 12c - cloud
http://www.oracle.com/us/products/database/overview/index.htmlhttp://www.oracle.com/technetwork/database/plug-into-cloud-wp-12c-1896100.pdf
April 9, 20233
SQL new features
SEQUENCE as default column value IDENTITY column VARCHAR2, NVARCHAR2 32K limit LIMIT, OFFSET support for paging Invisible column support Inline PL/SQL function within SQL WITH
expression
April 9, 20234
SEQUENCE as default col value
create sequence test_seq start with 1increment by 1;create table test_table(
id number default test_seq.nextval primary key);http://docs.oracle.com/cd/E16655_01/server.121/e17209/statements_7002.htm#SQLRF54458
April 9, 20235
IDENTITY column
MySQL,MS SQL Server auto increment/identitycreate table test_table(
id number generated by default on null as identity, name varchar2(10))insert into test_table(name) values(‘ramin’)insert into test_table(id,name) values(null, ‘ramin’)
http://docs.oracle.com/cd/E16655_01/gateways.121/e22508/migr_tools_feat.htm#DRDAA109
April 9, 20236
VARCHAR2,NVARCHAR2 32K limit
32767 character supportVARCHAR2, NVARCHAR2, RAW
Initialization paramMAX_STRING_SIZE = EXTENDED
http://docs.oracle.com/cd/E16655_01/server.121/e17209/sql_elements001.htm#SQLRF55623
April 9, 20237
LIMIT, OFFSET support
select *from (
select rownum rn, id, e.* from employees e )where rn between 1 AND 10order by 1;
April 9, 20238
LIMIT, OFFSET support
April 9, 20239
LIMIT, OFFSET support
April 9, 202310
SELECT employee_id, last_nameFROM employeesORDER BY salaryFETCH FIRST 10 ROWS ONLY;
SELECT employee_id, last_nameFROM employeesORDER BY salaryOFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY;
LIMIT, OFFSET support
April 9, 202311
SELECT employee_id, last_name, salaryFROM employeesORDER BY salaryFETCH FIRST 5 PERCENT ROWS WITH TIES;
http://docs.oracle.com/cd/E16655_01/server.121/e17209/statements_10002.htm#SQLRF55636
Invisible column
April 9, 202312
create table app_user(id number generated by default on
null as identity,username varchar2(100) not null,passwd varchar(100) invisible);select * from app_user;
http://docs.oracle.com/cd/E16655_01/server.121/e17636/tables.htm#ADMIN13866
Inline PL/SQL function WITH
April 9, 202313
withfunction sqr(p_num in number)
return number is begin return p_num * p_num; end;select u.user_id, sqr(u.user_id) from all_userswhere rownum <= 10;2.5-3x performance improvementhttp://docs.oracle.com/cd/E16655_01/server.121/e17209/statements_10002.htm#SQLRF55665
PL/SQL new features
April 9, 202314
New way for returning cursor Modularity with ACCESSIBLE BY New UTL_CALL_STACK package Using PL/SQL types in SQL context Result cache support for functions with
invoker’s right
New way for returning cursor
April 9, 202315
create procedure get_customer_order_listas
cur_customer sys_refcursor;cur_order sys_refcursor;
begin open cur_customer for select * from customer;
open cur_order for select * from order;
dbms_sql.return_result(cur_customer); dbms_sql.return_result(cur_order);end;
New way for returning cursor
April 9, 202316
// sample JDBC codeString sql = “begin get_customer_order_list; end;”;Connection con = datasource.getConnection();PreparedStatement ps = con.prepareStatement();ps.executeQuery(sql);while(ps.getMoreResults()) {
ResultSet rs = ps.getResultSet(); while(rs.next()) {
… read columns}
}
Modularity with ACCESSIBLE BY
April 9, 202317
package pkg_api;package pkg_api_utility;
pkg_api_utility is considered to be used only by pkg_api
ACCESSİBLE BY
Modularity with ACCESSIBLE BY
April 9, 202318
CREATE OR REPLACE PACKAGE pkg_api_utilityACCESSIBLE BY (pkg_api)IS PROCEDURE h1; PROCEDURE h2;END pkg_api_utility;
CREATE OR REPLACE PACKAGE BODY pkg_api_utilityIS PROCEDURE h1 IS BEGIN DBMS_OUTPUT.PUT_LINE('Helper procedure h1'); END; PROCEDURE h2 IS BEGIN DBMS_OUTPUT.PUT_LINE('Helper procedure h2'); END;END pkg_api_utility;
Modularity with ACCESSIBLE BY
April 9, 202319
beginpkg_api.p1;pkg_api.p2;
end;begin
pkg_api_utility.h1;pkg_api_utility.h2;
end;
ORA-06550PLS-00904: insufficient privilege to access object PKG_API_UTILITY
UTL_CALLSTACK package
April 9, 202320
DBMS_UTILITY functions related to call/error stack:–FORMAT_CALL_STACK–FORMAT_ERROR_STACK–FORMAT_ERROR_BACKTRACE
New package: UTL_CALLSTACK
http://docs.oracle.com/cd/E16655_01/appdev.121/e17602/u_call_stack.htm#ARPLS74078
Result cache support for functions with invoker’s right
April 9, 202321
In Oracle Database 11g Release 2 (11.2), only definer's rights PL/SQL functions could be result cached. Now, invoker's rights PL/SQL functions can also be result cached. (The identity of the invoking user is implicitly added to the key of the result.)http://docs.oracle.com/cd/E16655_01/appdev.121/e17622/release_changes.htm#LNPLS110
Java new features
April 9, 202322
PL/SQL boolean support in JDBC driver PL/SQL package level collection
support
Package level collection support
April 9, 202323
create or replace package TEST_PKG is type V_TYP is varray(10) of varchar2(200); type R_TYP is record(c1 pls_integer, c2 varchar2(100)); procedure VARR_PROC(p1 in V_TYP, p2 OUT V_TYP); procedure REC_PROC(p1 in R_TYP, p2 OUT R_TYP);end;/
Package level collection support
April 9, 202324
create or replace package body TEST_PKG is procedure VARR_PROC(p1 in V_TYP,
p2 OUT V_TYP) is begin p2 := p1; end; procedure REC_PROC(p1 in R_TYP,
p2 OUT R_TYP) is begin p2 := p1; end;end;
JDBC code
April 9, 202325
CallableStatement cstmt = null; try { cstmt = conn.prepareCall("{ call TEST_PKG.VARR_PROC(?,?) }");Array arr = ((OracleConnection)conn).createArray("TEST_PKG.V_TYP", new String[]{"A", "B"}); cstmt.setArray(1, arr); cstmt.registerOutParameter(2, Types.ARRAY, "TEST_PKG.V_TYP"); cstmt.execute(); //get PLSQL VARRAY type out parameter value Array outArr = cstmt.getArray(2);} catch( Exception e) { e.printStackTrace();}
JDBC code
April 9, 202326
try { cstmt = conn.prepareCall("{ call TEST_PKG.REC_PROC(?,?) }"); //PLSQL RECORD type binding Struct struct = conn.createStruct("TEST_PKG.R_TYP", new Object[]{12345, "B"}); cstmt.setObject(1, struct); cstmt.registerOutParameter(2, Types.STRUCT, "TEST_PKG.R_TYP"); cstmt.execute(); //get PLSQL RECORD type out parameter value Struct outStruct = (Struct)cstmt.getObject(2);} catch( Exception e) { e.printStackTrace();}
JDBC code
April 9, 202327
CREATE OR REPLACE PACKAGE PACK1 AS TYPE EMPLOYEE_ROWTYPE_ARRAY IS TABLE OF EMPLOYEES%ROWTYPE;END PACK1;
CallableStatement cstmt = conn.prepareCall("BEGIN SELECT * BULK COLLECT INTO :1 FROM EMPLOYEE; END;");cstmt.registerOutParameter(1,OracleTypes.ARRAY, "PACK1.EMPLOYEE_ROWTYPE_ARRAY");cstmt.execute();Array a = cstmt.getArray(1);
References
April 9, 202328
http://docs.oracle.com/cd/E16655_01/appdev.121/e17622/release_changes.htm
http://www.toadworld.com/platforms/oracle/b/weblog/archive/2013/07/01/oracle-database-12c-new-pl-sql-features.aspx
http://docs.oracle.com/cd/E16655_01/java.121/e17657/apxref.htm#CHEIIJCC
http://www.oracle-base.com/articles/12c/with-clause-enhancements-12cr1.php
Q&A
?