SlideShare ist ein Scribd-Unternehmen logo
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
What's New in SQL und PL/SQL
in Oracle Database 12c Release 2
Ulrike Schwinn
Oracle Deutschland BV &CO K.G.
Ulrike.Schwinn@oracle.com
twitter: @uschwinn
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Agenda
SQL
PL/SQL
Verschiedenes
1
2
3
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Grenze für Long Identifiers
• Statt 30 Bytes nun 128 Bytes
• Bedeutet 392 bei zusammengesetzten Identifiers wie
• Alle Limits findet man im PL/SQL Handbuch
http://docs.oracle.com/database/122/LNPLS/plsql-program-limits.htm#LNPLS018
SQL> set serveroutput on
SQL> EXEC DBMS_OUTPUT.PUT_LINE(ORA_MAX_NAME_LEN_SUPPORTED);
128
PL/SQL procedure successfully completed.
"schema"."table"."column"
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Anforderung „Unterschiedliche Einträge in den Spalten?“
• Spontan ... mit count distinct...
• Data Dictionary USER_TAB_COLUMNS und Spalte NUM_DISTINCT
SQL> select count(distinct(prod_id)) from sales;
COUNT(DISTINCT(PROD_ID))
------------------------
72
SQL> select column_name, num_distinct
from user_tab_columns where table_name='SALES';
COLUMN_NAME NUM_DISTINCT
------------------------------ ------------
PROD_ID 72
CUST_ID 7059
TIME_ID 1460
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
APPROX_COUNT_DISTINCT
• Alle skalare Datentypen sind möglich.
SQL> select approx_count_distinct(prod_id)from sales;
APPROX_COUNT_DISTINCT(PROD_ID)
----------------------------------------
72
Plan hash value: 2087281841
---------------------------------------------------------
| Id | Operation | Name |
---------------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT GROUP BY APPROX | |
...
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Und in 12.2 ...
• Keine Code Anpassung mehr erforderlich – nur Sessionparameter einstellen
• Weitere Approximate Query Processing Funktionen sind in 12.2 verfügbar
SQL> alter session set APPROX_FOR_COUNT_DISTINCT = true;
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Nützliche Funktionen: String Aggregation
• Wie kann man Strings aggregieren?
– Eigene Funktion schreiben
– Ab 11g Release 2 mit analytische Funktion listagg
FOR cur_rec IN (SELECT ename FROM emp WHERE deptno = p_deptno) LOOP l_text
:= l_text || ',' || cur_rec.ename; END LOOP; ….
select deptno, LISTAGG(ename, ',')
WITHIN GROUP (ORDER BY ename) AS employees
from emp group by deptno;
DEPTNO EMPLOYEES
---------- --------------------------------------------------
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Und in 12.2 mehr Kontrolle im Fehlerfall
• listagg bietet nun Kontrolle über den Return Wert, falls maximale
Länge erreicht wird … zuvor
nun
ORA-01489: Das Ergebnis der Zeichenfolgenverkettung ist zu lang
01489. 00000 - "result of string concatenation is too long"
*Cause: String concatenation result is more than the maximum size.
*Action: Make sure that the result is less than the maximum size.
SQL> select listagg(s, ';' on overflow truncate '...' with count)
within group (order by r)
from (select rownum r , 'x' s from dual connect by level <2002);
x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;
x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;...(16)
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Und in 12.2 mehr Kontrolle im Fehlerfall
• Auch für Funktionen wie
to_binary_double, to_binary_float, to_date, to_dsinterval,
to_number, to_timestamp to_timestamp_tz, to_yminterval
• Neue Funktion validate_conversion
select to_number(hiredate default 1000 on conversion error)
from emp where rownum<2;
select validate_conversion('1.11.2016' as number) from dual;
select validate_conversion('1000' as number) from dual;
select validate_conversion('1000' as number) from dual;
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Case-Insensitive Datenbank vor 12c Release 2
• Case insensitives Verhalten ist kein Default
• Möglich mit nls_upper, nls_lower in Kombination mit nls_sort
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Case-Insensitive Datenbank
• Case Insensitivität als Tabelleneigenschaft
• Voraussetzung: EXTENDED bei MAX_STRING_SIZE
• Im Moment nur möglich mit dynamischen eingebetteten SQL Statements
create table tab_ci (n number,
wort varchar2(100) collate binary_ci)
SQL> select * from tab_ci where wort='Klein'
N WORT
---------- ----------
1 klein
2 KLEIN
3 Klein
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Ausführungsplan
• Transparenz im Ausführungsplan
Execution Plan
----------------------------------------------------------
Plan hash value: 321651591
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 65 | 3 (0) | 00:00:01 |
|* 1 | TABLE ACCESS FULL| TAB_CI | 1 | 65 | 3 (0) | 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
--------------------------------------------------- 1 -
filter(NLSSORT("WORT",'nls_sort=''BINARY_CI''')=HEXTORAW('6B6C656 96E00'))
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Case-Insensitive Datenbank und Indizes
• Case Insensitivität by Default!
• Hinweise:
–Gilt für NLS_SORT wie GERMAN, XGERMAN, XGERMAN_CI, FRENCH,
FRENCH_M_AI usw.
SQL> create index i_tab_ci on tab_ci (wort);
Index created.
SQL> select index_type from user_indexes where index_name='I_TAB_CI';
INDEX_TYPE
---------------------------
FUNCTION-BASED NORMAL
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Agenda
SQL
PL/SQL
Verschiedenes
1
2
3
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Statische PL/SQL Ausdrücke
-- Ora_Max_Name_Len ist vordefiniert in DBMS_Standard
One_Part varchar2(Ora_Max_Name_Len + 2);
Two_Part varchar2(2*(Ora_Max_Name_Len + 2) + 1);
begin
One_Part := '"My Table"';
Two_Part := '"My Schema"'||'.'||One_Part;
• In der Deklaration waren zuvor nur Literale erlaubt
• Nun sind statische PL/SQL Ausdrücke möglich
–Mit statischen Operatoren wie +,-, *, <,> usw.
und Funktionen wie instr, abs, upper, to_char etc.
–In Typ Deklarationen wie VARCHAR2, NUMBER, VARRAY etc.
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
• Jetzt auch in Unterprogrammen einer Package Spezifikation möglich
Führt zu : PLS-00904: insufficient privilege to access object A
White Lists mit ACCESSIBLE BY
package p authid definer is
function a return varchar2 deterministic accessible by (x);
procedure b;
end p;
package body q is
procedure a is
begin
DBMS_Output.Put_Line(p.a());
end a;
...
end q;
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
• Neues DEPRECATE Pragma Compilation für Packages, Subprogramme oder
Types die “deprecated” sind oder ersetzt (superseded) wurden.
Neues Pragma DEPRECATE
create or replace PACKAGE pack1 AS
$IF DBMS_DB_VERSION.VER_LE_11
$THEN
PROCEDURE proc1;
$ELSE
PROCEDURE proc1;
PRAGMA DEPRECATE(proc1, 'You must use p2 instead.');
$END
PROCEDURE proc2;
PROCEDURE proc3;
END pack1;
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
• Verwendung über
• Erzeugen des Package führt zu
Neues Pragma DEPRECATE in Aktion
SP2-0808: Package created with compilation warnings
SQL> sho err
Errors for PACKAGE PACK1:
LINE/COL ERROR
-------- -----------------------------------------------------------------
7/5 PLW-06019: entity PROC1 is deprecated
ALTER SESSION SET PLSQL_WARNINGS='ENABLE:(6019,6020,6021,6022)';
ALTER SESSION SET PLSQL_WARNINGS='enable:ALL';
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
• Weitere Nutzung führt zu
Neues Pragma DEPRECATE in Aktion
create or replace procedure pack2
as
begin
pack1.proc1;
end;
/
SP2-0804: Procedure created with compilation warnings
SQL> sho err
Errors for PROCEDURE PACK2:
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/1 PLW-06020: reference to a deprecated entity: PROC1 declared in
unit PACK1[6,15]. You must use p2 instead.
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
• Neues Package DBMS_PLSQL_CODE_COVERAGE hilft Daten über Block
Level Nutzung zu sammeln.
• Funktionsweise:
• 3 Hilftsabellen mit anlegen mit
DBMS_PLSQL_CODE_COVERAGE.CREATE_COVERAGE_TABLES
• Start mit DBMS_PLSQL_CODE_COVERAGE.START_COVERAGE
• Ausführungen
• Stop mit DBMS_PLSQL_CODE_COVERAGE.STOP_COVERAGE
Code Coverage Utility
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
• Programmläufe
Beispiel für Code Coverage
declare
Run_ID pls_integer not null := -1;
begin
Run_ID :=
DBMS_Plsql_Code_Coverage.Start_Coverage(Run_Comment=>'Run_001');
DBMS_Output.Put_Line(test(17));
DBMS_Output.Put_Line(test(0));
DBMS_Plsql_Code_Coverage.Stop_Coverage();
end;
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Beispiel für Code Coverage
1 function test(i in number) return number is
2 begin
3 return 1.0/i;
4 exception
5 when Zero_Divide then
6 return 42;
7 when others then
8 pragma Coverage('NOT_FEASIBLE');
9 raise;
10 end test;
SQL> select * from dbmspcc_blocks;
RUN_ID OBJECT_ID BLOCK LINE COL COVERED NOT_FEASIBLE
---------- ---------- ---------- ---------- ---------- ---------- ------------
1 82933 1 1 1 1 1
1 82933 2 5 8 1 1
1 82933 3 7 8 0 1
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Beispiel für Code Coverage mit mehr Informationen
set pagesize 1000
col object_name format a15
BREAK ON OBJECT_NAME ON OBJECT_TYPE on Block
select o.object_name, o.Object_type, d.run_id, d.block, covered, s.text
from dbmspcc_blocks d, all_objects o, all_source s
where s.owner='SCOTT' and
d.object_id = o.object_id and
s.name = o.Object_name and
s.type = o.object_type and
d.line = s.line
order by run_id, block;
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Das Ergebnis
OBJECT_NAME OBJECT_TYPE RUN_ID BLOCK COVERED
--------------- ----------------------- ---------- ---------- ----------
TEXT
--------------------------------------------------------------------------
TEST FUNCTION 1 1 1
function Recip(i in number) return number authid Definer is
1 2 1
when Zero_Divide then
1 3 0
when others then
2 1 1
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
• PLSCOPE_SETTINGS kontrolliert Cross-Referenzen und speichert PL/SQL
Source Code Identifier Daten mit Werten wie IDENTIFIERS:NONE|ALL
• Ab 12.2 werden jetzt auch SQL_ID und Identifier von statischem SQL gelistet
Beispiele
• Überprüfbar in USER_IDENTIFIERS und USER_STATEMENTS (neu)
'IDENTIFIERS:SQL, STATEMENTS:ALL'
'IDENTIFIERS:ALL, STATEMENTS:ALL'
PLSCOPE jetzt auch für Statements
'IDENTIFIERS:PLSQL, STATEMENTS:NONE'
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
• Identifiziert nun SQL über SQL_ID
• Der Bericht enthält SQL Execution Informationen für jeden Child Cursor
PLSQL Hierarchical Profiler
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
PLSQL Hierarchical Profiler
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JSON News
• Neues Handbuch: Database JSON Developer's Guide
• Partitionierung von JSON Daten
• SQL/JSON Funktionen und Bedingungen in PL/SQL
• SQL/JSON Funktionen können nun für GeoJSON verwendet werden
• JSON Spalten im In-Memory Column Store
• Materialized Views mit JSON Daten
• SQL/JSON Funktionen um JSON zu generieren
• OracleObjekttypen erlauben JSON Konstrukte und das Editieren in JSON
• Dataguide Features – sehr cool
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JSON News - Dataguide
• Dataguide erzeugen – mit oder ohne Textindex und als Grundlage für View
Creation
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JSON News - Dataguide
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
• “Drop edition” ist neu implementiert um das Stillegen eines Edition zu
ermöglichen.
• Beim Drop wird die Edition als UNUSABLE markiert.
• Jedes editioned Objekt das nicht mehr vererbt ist, wird später automatisch
gelöscht
• Falls kein Objekt mehr übrig ist, wird die Edition selbst gelöscht.
Automatisches Retiring von ungenutzten Editionen
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Agenda
SQL
PL/SQL
Verschiedenes
1
2
3
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Noch kurz zu den Werkzeugen
• SQL*Plus: Release 12.2
Standard, Erweiterungen in 12c R2 (History, Performance,CSV Format)
• SQL Developer 4.2
einfache Verbindung zu Cloud Services
besonders gut geeignet für Tuning, Ausführungspläne,
schnelle Objekt-Übersicht, SQL Generierung, Laden etc.
• SQLcl: 4.2.0 – das neue Linemode Werkzeug schlechthin
einfache Cloud Verbindungen, Scripting, Vorteile von graphischem
Interface, einfache Formatgenerierung etc
https://apex.oracle.com/pls/apex/germancommunities/dbacommunity/tipp/5481/index.html
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Weitere Informationen
• Deutschsprachiger Blog: http:/tinyurl.com/dbcommunity
– Inhaltsverzeichnis
• Database Online Documentation Library 12c Release 2 (12.2) :
http://docs.oracle.com/database/122/nav/portal_booklist.htm
– What‘s New Sections
• Monatl.Oracle Technology Update: http://tinyurl.com/oratech-monthly
• Twitter: @uschwinn, @oraclebudb
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

Weitere ähnliche Inhalte

Ähnlich wie What's new in SQL und PL/SQL in 12.2

Oracle12c für Entwickler
Oracle12c für EntwicklerOracle12c für Entwickler
Oracle12c für Entwickler
oraclebudb
 
Oracle Text 12c New Features
Oracle Text 12c New FeaturesOracle Text 12c New Features
Oracle Text 12c New Features
Ulrike Schwinn
 
Ausgewählte PL/SQL Packages (1)
Ausgewählte PL/SQL Packages (1)Ausgewählte PL/SQL Packages (1)
Ausgewählte PL/SQL Packages (1)
Ulrike Schwinn
 
Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)
Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)
Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)
Ulrike Schwinn
 
Angelika Gallwitz – IT-Tage 2015 – Statistische Auswertungen in Oracle mit S...
Angelika Gallwitz  – IT-Tage 2015 – Statistische Auswertungen in Oracle mit S...Angelika Gallwitz  – IT-Tage 2015 – Statistische Auswertungen in Oracle mit S...
Angelika Gallwitz – IT-Tage 2015 – Statistische Auswertungen in Oracle mit S...
Informatik Aktuell
 
Qualitätssicherung für APEX Anwendungen.pdf
Qualitätssicherung für APEX Anwendungen.pdfQualitätssicherung für APEX Anwendungen.pdf
Qualitätssicherung für APEX Anwendungen.pdf
Oliver Lemm
 
MySQL Performance Tuning für Oracle-DBA's
MySQL Performance Tuning für Oracle-DBA'sMySQL Performance Tuning für Oracle-DBA's
MySQL Performance Tuning für Oracle-DBA's
FromDual GmbH
 
Performance-Analyse mit Bordmitteln
Performance-Analyse mit BordmittelnPerformance-Analyse mit Bordmitteln
Performance-Analyse mit Bordmitteln
OPITZ CONSULTING Deutschland
 
Introduction into Oracle Data Pump 11g/12c - Export and Import Data
Introduction into Oracle Data Pump 11g/12c - Export and Import DataIntroduction into Oracle Data Pump 11g/12c - Export and Import Data
Introduction into Oracle Data Pump 11g/12c - Export and Import Data
Gunther Pippèrr
 
01 sqlplus
01 sqlplus01 sqlplus
01 sqlplus
Gunther Pippèrr
 
Automatisiertes disaster recovery testing mit der oracle cloud
Automatisiertes disaster recovery testing mit der oracle cloudAutomatisiertes disaster recovery testing mit der oracle cloud
Automatisiertes disaster recovery testing mit der oracle cloud
Trivadis
 
OSMC 2014: Monitoring von Netzwerkkomponenten mit check_nwc_health | Gerhard ...
OSMC 2014: Monitoring von Netzwerkkomponenten mit check_nwc_health | Gerhard ...OSMC 2014: Monitoring von Netzwerkkomponenten mit check_nwc_health | Gerhard ...
OSMC 2014: Monitoring von Netzwerkkomponenten mit check_nwc_health | Gerhard ...
NETWAYS
 
PureSQL APEX Connect
PureSQL APEX ConnectPureSQL APEX Connect
PureSQL APEX Connect
Trivadis
 
Pure SQL for batch processing
Pure SQL for batch processingPure SQL for batch processing
Pure SQL for batch processing
Andrej Pashchenko
 
Sensitive Daten in der Oracle Datenbank
Sensitive Daten in der Oracle DatenbankSensitive Daten in der Oracle Datenbank
Sensitive Daten in der Oracle Datenbank
Ulrike Schwinn
 
Qualitätsstandards in der Datenbankentwicklung.pdf
Qualitätsstandards in der Datenbankentwicklung.pdfQualitätsstandards in der Datenbankentwicklung.pdf
Qualitätsstandards in der Datenbankentwicklung.pdf
Oliver Lemm
 
Überblick zu Oracle Database 12c Release 2
Überblick zu Oracle Database 12c Release 2Überblick zu Oracle Database 12c Release 2
Überblick zu Oracle Database 12c Release 2
Ulrike Schwinn
 
Oracle Database 12c Release 2
Oracle Database 12c Release 2 Oracle Database 12c Release 2
Oracle Database 12c Release 2
oraclebudb
 
check_sap_health
check_sap_healthcheck_sap_health
check_sap_health
Gerhard Lausser
 
SQL Tuning Sets: Generieren, Verwenden, Transferieren, Szenarios
SQL Tuning Sets: Generieren, Verwenden, Transferieren, Szenarios SQL Tuning Sets: Generieren, Verwenden, Transferieren, Szenarios
SQL Tuning Sets: Generieren, Verwenden, Transferieren, Szenarios
Ulrike Schwinn
 

Ähnlich wie What's new in SQL und PL/SQL in 12.2 (20)

Oracle12c für Entwickler
Oracle12c für EntwicklerOracle12c für Entwickler
Oracle12c für Entwickler
 
Oracle Text 12c New Features
Oracle Text 12c New FeaturesOracle Text 12c New Features
Oracle Text 12c New Features
 
Ausgewählte PL/SQL Packages (1)
Ausgewählte PL/SQL Packages (1)Ausgewählte PL/SQL Packages (1)
Ausgewählte PL/SQL Packages (1)
 
Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)
Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)
Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)
 
Angelika Gallwitz – IT-Tage 2015 – Statistische Auswertungen in Oracle mit S...
Angelika Gallwitz  – IT-Tage 2015 – Statistische Auswertungen in Oracle mit S...Angelika Gallwitz  – IT-Tage 2015 – Statistische Auswertungen in Oracle mit S...
Angelika Gallwitz – IT-Tage 2015 – Statistische Auswertungen in Oracle mit S...
 
Qualitätssicherung für APEX Anwendungen.pdf
Qualitätssicherung für APEX Anwendungen.pdfQualitätssicherung für APEX Anwendungen.pdf
Qualitätssicherung für APEX Anwendungen.pdf
 
MySQL Performance Tuning für Oracle-DBA's
MySQL Performance Tuning für Oracle-DBA'sMySQL Performance Tuning für Oracle-DBA's
MySQL Performance Tuning für Oracle-DBA's
 
Performance-Analyse mit Bordmitteln
Performance-Analyse mit BordmittelnPerformance-Analyse mit Bordmitteln
Performance-Analyse mit Bordmitteln
 
Introduction into Oracle Data Pump 11g/12c - Export and Import Data
Introduction into Oracle Data Pump 11g/12c - Export and Import DataIntroduction into Oracle Data Pump 11g/12c - Export and Import Data
Introduction into Oracle Data Pump 11g/12c - Export and Import Data
 
01 sqlplus
01 sqlplus01 sqlplus
01 sqlplus
 
Automatisiertes disaster recovery testing mit der oracle cloud
Automatisiertes disaster recovery testing mit der oracle cloudAutomatisiertes disaster recovery testing mit der oracle cloud
Automatisiertes disaster recovery testing mit der oracle cloud
 
OSMC 2014: Monitoring von Netzwerkkomponenten mit check_nwc_health | Gerhard ...
OSMC 2014: Monitoring von Netzwerkkomponenten mit check_nwc_health | Gerhard ...OSMC 2014: Monitoring von Netzwerkkomponenten mit check_nwc_health | Gerhard ...
OSMC 2014: Monitoring von Netzwerkkomponenten mit check_nwc_health | Gerhard ...
 
PureSQL APEX Connect
PureSQL APEX ConnectPureSQL APEX Connect
PureSQL APEX Connect
 
Pure SQL for batch processing
Pure SQL for batch processingPure SQL for batch processing
Pure SQL for batch processing
 
Sensitive Daten in der Oracle Datenbank
Sensitive Daten in der Oracle DatenbankSensitive Daten in der Oracle Datenbank
Sensitive Daten in der Oracle Datenbank
 
Qualitätsstandards in der Datenbankentwicklung.pdf
Qualitätsstandards in der Datenbankentwicklung.pdfQualitätsstandards in der Datenbankentwicklung.pdf
Qualitätsstandards in der Datenbankentwicklung.pdf
 
Überblick zu Oracle Database 12c Release 2
Überblick zu Oracle Database 12c Release 2Überblick zu Oracle Database 12c Release 2
Überblick zu Oracle Database 12c Release 2
 
Oracle Database 12c Release 2
Oracle Database 12c Release 2 Oracle Database 12c Release 2
Oracle Database 12c Release 2
 
check_sap_health
check_sap_healthcheck_sap_health
check_sap_health
 
SQL Tuning Sets: Generieren, Verwenden, Transferieren, Szenarios
SQL Tuning Sets: Generieren, Verwenden, Transferieren, Szenarios SQL Tuning Sets: Generieren, Verwenden, Transferieren, Szenarios
SQL Tuning Sets: Generieren, Verwenden, Transferieren, Szenarios
 

What's new in SQL und PL/SQL in 12.2

  • 1.
  • 2. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. What's New in SQL und PL/SQL in Oracle Database 12c Release 2 Ulrike Schwinn Oracle Deutschland BV &CO K.G. Ulrike.Schwinn@oracle.com twitter: @uschwinn
  • 3. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Agenda SQL PL/SQL Verschiedenes 1 2 3
  • 4. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Grenze für Long Identifiers • Statt 30 Bytes nun 128 Bytes • Bedeutet 392 bei zusammengesetzten Identifiers wie • Alle Limits findet man im PL/SQL Handbuch http://docs.oracle.com/database/122/LNPLS/plsql-program-limits.htm#LNPLS018 SQL> set serveroutput on SQL> EXEC DBMS_OUTPUT.PUT_LINE(ORA_MAX_NAME_LEN_SUPPORTED); 128 PL/SQL procedure successfully completed. "schema"."table"."column"
  • 5. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Anforderung „Unterschiedliche Einträge in den Spalten?“ • Spontan ... mit count distinct... • Data Dictionary USER_TAB_COLUMNS und Spalte NUM_DISTINCT SQL> select count(distinct(prod_id)) from sales; COUNT(DISTINCT(PROD_ID)) ------------------------ 72 SQL> select column_name, num_distinct from user_tab_columns where table_name='SALES'; COLUMN_NAME NUM_DISTINCT ------------------------------ ------------ PROD_ID 72 CUST_ID 7059 TIME_ID 1460
  • 6. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. APPROX_COUNT_DISTINCT • Alle skalare Datentypen sind möglich. SQL> select approx_count_distinct(prod_id)from sales; APPROX_COUNT_DISTINCT(PROD_ID) ---------------------------------------- 72 Plan hash value: 2087281841 --------------------------------------------------------- | Id | Operation | Name | --------------------------------------------------------- | 0 | SELECT STATEMENT | | | 1 | SORT GROUP BY APPROX | | ...
  • 7. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Und in 12.2 ... • Keine Code Anpassung mehr erforderlich – nur Sessionparameter einstellen • Weitere Approximate Query Processing Funktionen sind in 12.2 verfügbar SQL> alter session set APPROX_FOR_COUNT_DISTINCT = true;
  • 8. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Nützliche Funktionen: String Aggregation • Wie kann man Strings aggregieren? – Eigene Funktion schreiben – Ab 11g Release 2 mit analytische Funktion listagg FOR cur_rec IN (SELECT ename FROM emp WHERE deptno = p_deptno) LOOP l_text := l_text || ',' || cur_rec.ename; END LOOP; …. select deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees from emp group by deptno; DEPTNO EMPLOYEES ---------- -------------------------------------------------- 10 CLARK,KING,MILLER 20 ADAMS,FORD,JONES,SCOTT,SMITH 30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
  • 9. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Und in 12.2 mehr Kontrolle im Fehlerfall • listagg bietet nun Kontrolle über den Return Wert, falls maximale Länge erreicht wird … zuvor nun ORA-01489: Das Ergebnis der Zeichenfolgenverkettung ist zu lang 01489. 00000 - "result of string concatenation is too long" *Cause: String concatenation result is more than the maximum size. *Action: Make sure that the result is less than the maximum size. SQL> select listagg(s, ';' on overflow truncate '...' with count) within group (order by r) from (select rownum r , 'x' s from dual connect by level <2002); x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;...(16)
  • 10. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Und in 12.2 mehr Kontrolle im Fehlerfall • Auch für Funktionen wie to_binary_double, to_binary_float, to_date, to_dsinterval, to_number, to_timestamp to_timestamp_tz, to_yminterval • Neue Funktion validate_conversion select to_number(hiredate default 1000 on conversion error) from emp where rownum<2; select validate_conversion('1.11.2016' as number) from dual; select validate_conversion('1000' as number) from dual; select validate_conversion('1000' as number) from dual;
  • 11. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Case-Insensitive Datenbank vor 12c Release 2 • Case insensitives Verhalten ist kein Default • Möglich mit nls_upper, nls_lower in Kombination mit nls_sort
  • 12. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Case-Insensitive Datenbank • Case Insensitivität als Tabelleneigenschaft • Voraussetzung: EXTENDED bei MAX_STRING_SIZE • Im Moment nur möglich mit dynamischen eingebetteten SQL Statements create table tab_ci (n number, wort varchar2(100) collate binary_ci) SQL> select * from tab_ci where wort='Klein' N WORT ---------- ---------- 1 klein 2 KLEIN 3 Klein
  • 13. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Ausführungsplan • Transparenz im Ausführungsplan Execution Plan ---------------------------------------------------------- Plan hash value: 321651591 ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 65 | 3 (0) | 00:00:01 | |* 1 | TABLE ACCESS FULL| TAB_CI | 1 | 65 | 3 (0) | 00:00:01 | ---------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter(NLSSORT("WORT",'nls_sort=''BINARY_CI''')=HEXTORAW('6B6C656 96E00'))
  • 14. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Case-Insensitive Datenbank und Indizes • Case Insensitivität by Default! • Hinweise: –Gilt für NLS_SORT wie GERMAN, XGERMAN, XGERMAN_CI, FRENCH, FRENCH_M_AI usw. SQL> create index i_tab_ci on tab_ci (wort); Index created. SQL> select index_type from user_indexes where index_name='I_TAB_CI'; INDEX_TYPE --------------------------- FUNCTION-BASED NORMAL
  • 15. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Agenda SQL PL/SQL Verschiedenes 1 2 3
  • 16. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Statische PL/SQL Ausdrücke -- Ora_Max_Name_Len ist vordefiniert in DBMS_Standard One_Part varchar2(Ora_Max_Name_Len + 2); Two_Part varchar2(2*(Ora_Max_Name_Len + 2) + 1); begin One_Part := '"My Table"'; Two_Part := '"My Schema"'||'.'||One_Part; • In der Deklaration waren zuvor nur Literale erlaubt • Nun sind statische PL/SQL Ausdrücke möglich –Mit statischen Operatoren wie +,-, *, <,> usw. und Funktionen wie instr, abs, upper, to_char etc. –In Typ Deklarationen wie VARCHAR2, NUMBER, VARRAY etc.
  • 17. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. • Jetzt auch in Unterprogrammen einer Package Spezifikation möglich Führt zu : PLS-00904: insufficient privilege to access object A White Lists mit ACCESSIBLE BY package p authid definer is function a return varchar2 deterministic accessible by (x); procedure b; end p; package body q is procedure a is begin DBMS_Output.Put_Line(p.a()); end a; ... end q;
  • 18. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. • Neues DEPRECATE Pragma Compilation für Packages, Subprogramme oder Types die “deprecated” sind oder ersetzt (superseded) wurden. Neues Pragma DEPRECATE create or replace PACKAGE pack1 AS $IF DBMS_DB_VERSION.VER_LE_11 $THEN PROCEDURE proc1; $ELSE PROCEDURE proc1; PRAGMA DEPRECATE(proc1, 'You must use p2 instead.'); $END PROCEDURE proc2; PROCEDURE proc3; END pack1;
  • 19. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. • Verwendung über • Erzeugen des Package führt zu Neues Pragma DEPRECATE in Aktion SP2-0808: Package created with compilation warnings SQL> sho err Errors for PACKAGE PACK1: LINE/COL ERROR -------- ----------------------------------------------------------------- 7/5 PLW-06019: entity PROC1 is deprecated ALTER SESSION SET PLSQL_WARNINGS='ENABLE:(6019,6020,6021,6022)'; ALTER SESSION SET PLSQL_WARNINGS='enable:ALL';
  • 20. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. • Weitere Nutzung führt zu Neues Pragma DEPRECATE in Aktion create or replace procedure pack2 as begin pack1.proc1; end; / SP2-0804: Procedure created with compilation warnings SQL> sho err Errors for PROCEDURE PACK2: LINE/COL ERROR -------- ----------------------------------------------------------------- 4/1 PLW-06020: reference to a deprecated entity: PROC1 declared in unit PACK1[6,15]. You must use p2 instead.
  • 21. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. • Neues Package DBMS_PLSQL_CODE_COVERAGE hilft Daten über Block Level Nutzung zu sammeln. • Funktionsweise: • 3 Hilftsabellen mit anlegen mit DBMS_PLSQL_CODE_COVERAGE.CREATE_COVERAGE_TABLES • Start mit DBMS_PLSQL_CODE_COVERAGE.START_COVERAGE • Ausführungen • Stop mit DBMS_PLSQL_CODE_COVERAGE.STOP_COVERAGE Code Coverage Utility
  • 22. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. • Programmläufe Beispiel für Code Coverage declare Run_ID pls_integer not null := -1; begin Run_ID := DBMS_Plsql_Code_Coverage.Start_Coverage(Run_Comment=>'Run_001'); DBMS_Output.Put_Line(test(17)); DBMS_Output.Put_Line(test(0)); DBMS_Plsql_Code_Coverage.Stop_Coverage(); end;
  • 23. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Beispiel für Code Coverage 1 function test(i in number) return number is 2 begin 3 return 1.0/i; 4 exception 5 when Zero_Divide then 6 return 42; 7 when others then 8 pragma Coverage('NOT_FEASIBLE'); 9 raise; 10 end test; SQL> select * from dbmspcc_blocks; RUN_ID OBJECT_ID BLOCK LINE COL COVERED NOT_FEASIBLE ---------- ---------- ---------- ---------- ---------- ---------- ------------ 1 82933 1 1 1 1 1 1 82933 2 5 8 1 1 1 82933 3 7 8 0 1
  • 24. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Beispiel für Code Coverage mit mehr Informationen set pagesize 1000 col object_name format a15 BREAK ON OBJECT_NAME ON OBJECT_TYPE on Block select o.object_name, o.Object_type, d.run_id, d.block, covered, s.text from dbmspcc_blocks d, all_objects o, all_source s where s.owner='SCOTT' and d.object_id = o.object_id and s.name = o.Object_name and s.type = o.object_type and d.line = s.line order by run_id, block;
  • 25. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Das Ergebnis OBJECT_NAME OBJECT_TYPE RUN_ID BLOCK COVERED --------------- ----------------------- ---------- ---------- ---------- TEXT -------------------------------------------------------------------------- TEST FUNCTION 1 1 1 function Recip(i in number) return number authid Definer is 1 2 1 when Zero_Divide then 1 3 0 when others then 2 1 1
  • 26. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. • PLSCOPE_SETTINGS kontrolliert Cross-Referenzen und speichert PL/SQL Source Code Identifier Daten mit Werten wie IDENTIFIERS:NONE|ALL • Ab 12.2 werden jetzt auch SQL_ID und Identifier von statischem SQL gelistet Beispiele • Überprüfbar in USER_IDENTIFIERS und USER_STATEMENTS (neu) 'IDENTIFIERS:SQL, STATEMENTS:ALL' 'IDENTIFIERS:ALL, STATEMENTS:ALL' PLSCOPE jetzt auch für Statements 'IDENTIFIERS:PLSQL, STATEMENTS:NONE'
  • 27. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. • Identifiziert nun SQL über SQL_ID • Der Bericht enthält SQL Execution Informationen für jeden Child Cursor PLSQL Hierarchical Profiler
  • 28. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. PLSQL Hierarchical Profiler
  • 29. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JSON News • Neues Handbuch: Database JSON Developer's Guide • Partitionierung von JSON Daten • SQL/JSON Funktionen und Bedingungen in PL/SQL • SQL/JSON Funktionen können nun für GeoJSON verwendet werden • JSON Spalten im In-Memory Column Store • Materialized Views mit JSON Daten • SQL/JSON Funktionen um JSON zu generieren • OracleObjekttypen erlauben JSON Konstrukte und das Editieren in JSON • Dataguide Features – sehr cool
  • 30. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JSON News - Dataguide • Dataguide erzeugen – mit oder ohne Textindex und als Grundlage für View Creation
  • 31. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JSON News - Dataguide
  • 32. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. • “Drop edition” ist neu implementiert um das Stillegen eines Edition zu ermöglichen. • Beim Drop wird die Edition als UNUSABLE markiert. • Jedes editioned Objekt das nicht mehr vererbt ist, wird später automatisch gelöscht • Falls kein Objekt mehr übrig ist, wird die Edition selbst gelöscht. Automatisches Retiring von ungenutzten Editionen
  • 33. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Agenda SQL PL/SQL Verschiedenes 1 2 3
  • 34. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Noch kurz zu den Werkzeugen • SQL*Plus: Release 12.2 Standard, Erweiterungen in 12c R2 (History, Performance,CSV Format) • SQL Developer 4.2 einfache Verbindung zu Cloud Services besonders gut geeignet für Tuning, Ausführungspläne, schnelle Objekt-Übersicht, SQL Generierung, Laden etc. • SQLcl: 4.2.0 – das neue Linemode Werkzeug schlechthin einfache Cloud Verbindungen, Scripting, Vorteile von graphischem Interface, einfache Formatgenerierung etc https://apex.oracle.com/pls/apex/germancommunities/dbacommunity/tipp/5481/index.html
  • 35. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Weitere Informationen • Deutschsprachiger Blog: http:/tinyurl.com/dbcommunity – Inhaltsverzeichnis • Database Online Documentation Library 12c Release 2 (12.2) : http://docs.oracle.com/database/122/nav/portal_booklist.htm – What‘s New Sections • Monatl.Oracle Technology Update: http://tinyurl.com/oratech-monthly • Twitter: @uschwinn, @oraclebudb
  • 36. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

Hinweis der Redaktion

  1. Row Generator: Insert into budb SELECT ROWNUM, 'x' || FROM ( SELECT 1 budb FROM dual CONNECT BY LEVEL <= 2000 )