IEEE Day 2013 Oracle Database 12c: new features for developers

1,936 views

Published on

IEEE Day 2013 Baku
Oracle Database 12c: new features PL/SQL and Java developers.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,936
On SlideShare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
36
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

IEEE Day 2013 Oracle Database 12c: new features for developers

  1. 1. IEEE Day 2013 Ramin Orujov ICT/Internal Applications Team Head Azercell Telecom SCJP 6, OCE Java EE 6 WCD www.linkedin.com/in/raminorujov 01 October 2013, Qafqaz University Oracle database 12c: New features for developers
  2. 2. About me Senior software developer Internal Applications Team Head@Azercell Teacher @ Qafqaz University CE dept. Co-manager of AZEROUG Founder and manager of AZERJUG October 1, 20132
  3. 3. Oracle database platforms Oracle 9i – internet Oracle 10g/11g – grid Oracle 12c - cloud http://www.oracle.com/us/products/databas http://www.oracle.com/technetwork/databas October 1, 20133
  4. 4. 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 October 1, 20134
  5. 5. SEQUENCE as default col value create sequence test_seq start with 1 increment by 1; create table test_table( id number default test_seq.nextval primary key ); http://docs.oracle.com/cd/E16655_01/server SQLRF54458 October 1, 20135
  6. 6. IDENTITY column MySQL,MS SQL Server auto increment/identity create 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/ DRDAA109 October 1, 20136
  7. 7. VARCHAR2,NVARCHAR2 32K limit 32767 character support VARCHAR2, NVARCHAR2, RAW Initialization param MAX_STRING_SIZE = EXTENDED http://docs.oracle.com/cd/E16655_01/server October 1, 20137
  8. 8. LIMIT, OFFSET support select * from ( select rownum rn, id, e.* from employees e ) where rn between 1 AND 10 order by 1; October 1, 20138
  9. 9. LIMIT, OFFSET support October 1, 20139
  10. 10. LIMIT, OFFSET support October 1, 201310 SELECT employee_id, last_name FROM employees ORDER BY salary FETCH FIRST 10 ROWS ONLY; SELECT employee_id, last_name FROM employees ORDER BY salary OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY;
  11. 11. LIMIT, OFFSET support October 1, 201311 SELECT employee_id, last_name, salary FROM employees ORDER BY salary FETCH FIRST 5 PERCENT ROWS WITH TIES; http://docs.oracle.com/cd/E16655_01/server.121
  12. 12. Invisible column October 1, 201312 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
  13. 13. Inline PL/SQL function WITH October 1, 201313 with function 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_users where rownum <= 10; 2.5-3x performance improvement http://docs.oracle.com/cd/E16655_01/server.121/e17
  14. 14. PL/SQL new features October 1, 201314  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
  15. 15. New way for returning cursor October 1, 201315 create procedure get_customer_order_list as 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;
  16. 16. New way for returning cursor October 1, 201316 // sample JDBC code String 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 } }
  17. 17. Modularity with ACCESSIBLE BY October 1, 201317 package pkg_api; package pkg_api_utility; pkg_api_utility is considered to be used only by pkg_api ACCESSİBLE BY
  18. 18. Modularity with ACCESSIBLE BY October 1, 201318 CREATE OR REPLACE PACKAGE pkg_api_utility ACCESSIBLE BY (pkg_api) IS PROCEDURE h1; PROCEDURE h2; END pkg_api_utility; CREATE OR REPLACE PACKAGE BODY pkg_api_utility IS 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;
  19. 19. Modularity with ACCESSIBLE BY October 1, 201319 begin pkg_api.p1; pkg_api.p2; end; begin pkg_api_utility.h1; pkg_api_utility.h2; end; ORA-06550 PLS-00904: insufficient privilege to access object PKG_API_UTILITY
  20. 20. UTL_CALLSTACK package October 1, 201320 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/
  21. 21. Result cache support for functions with invoker’s right October 1, 201321 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/appde v.121/e17622/release_changes.htm#LNPLS1 10
  22. 22. Java new features October 1, 201322  PL/SQL boolean support in JDBC driver  PL/SQL package level collection support
  23. 23. Package level collection support October 1, 201323 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; /
  24. 24. Package level collection support October 1, 201324 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;
  25. 25. JDBC code October 1, 201325 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(); }
  26. 26. JDBC code October 1, 201326 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(); }
  27. 27. JDBC code October 1, 201327 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);
  28. 28. References October 1, 201328  http://docs.oracle.com/cd/E16655_01/appdev.121 /e17622/release_changes.htm  http://www.toadworld.com/platforms/oracle/b/we blog/archive/2013/07/01/oracle-database-12c- new-pl-sql-features.aspx  http://docs.oracle.com/cd/E16655_01/java.121/e1 7657/apxref.htm#CHEIIJCC  http://www.oracle-base.com/articles/12c/with- clause-enhancements-12cr1.php
  29. 29. Q&A ?

×