+ All Categories
Transcript
Page 1: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Oracle Developer Monthly Datenbank-Update für Anwendungsentwickler Februar 2016

Carsten Czarski Business Unit Database Oracle Deutschland B.V. & Co KG

Page 2: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

http://tinyurl.com/ModernAppDev12c http://tinyurl.com/oracloudnow

Page 3: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

http://tinyurl.com/ModernAppDev12c http://tinyurl.com/modernappdev

Page 4: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Wichtige Termine

• 10. März APEX Meetup in Hamburg – mit Marc Sewtz

• 15. März Oracle Data Warehouse Konferenz 2016 in Mainz – 2 Tage

• 15. März "APEX Startup" Hands-On Workshop bei der MT AG in Ratingen

• 16. März "APEX Startup" Hands-On Workshop bei Oracle in Dreieich

• 17. März APEX Meetup in München – mit Marc Sewtz

• 20. April Oracle IT Transformation Summit – München

• 26. April DOAG APEX Connect 2016 in Berlin

• Mai 2016 DOAG 2016 Datenbank in Düsseldorf

• Juni 2016 DOAG 2016 BI in Bonn

Page 5: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Digital Transformation IT Summit – 20. April 2016 München

http://digitaltransformationit.oracle.com/munich/de/

Page 6: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

APEX Competition: Wer baut das coolste Dashboard?

http://apexcompetition.org

Page 7: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

APEX Competition: Wer baut das coolste Dashboard?

• Erstellt ein "Dashboard" mit APEX auf vorgegebenen Daten

• APEX-Diagramme, Open Source, D3.js, Reports und mehr

• Gewinner werden auf der APEX Connect 2016 in Berlin geehrt

Page 8: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Aktuelle Software Release und Patchstände

• Oracle Datenbank 12.1.0.2

• SQL Developer 4.1.3

• SQLcl 4.2.0.16 (18. Februar 2016)

• SQL Developer Data Modeler 4.1.3*

• node-oracledb 1.6*

• Application Express 5.0.3*

• Oracle Rest Data Services 3.0.3*

• Oracle NoSQL DB 12.1.3.5.2

* Bug Fix Release

Page 9: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsverarbeitung in der Oracle-Datenbank

• Datentypen

– DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE

• Datumsformate

– NLS-Formatmasken, NLS-Datumssprache, Datums-Literale

• Datumsarithmetik

– Arbeiten mit Dezimalzahlen oder mit INTERVAL-Datentypen

Page 10: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsverarbeitung

• Kodierung eines DATE SQL> select sysdate, dump(sysdate) dmp from dual; SYSDATE DMP --------------------------- ---------------------------------------- 22.02.2016 09:50:36 Typ=13 Len=8: 224,7,2,22,9,50,36,0 1 rows selected.

E0,07 Hex 07E0 2016

Page 11: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsverarbeitung

• TIMESTAMP (ohne Zeitzone)

• TIMESTAMP WITH TIME ZONE

SQL> select systimestamp, dump(systimestamp) dmp from dual SYSTIMESTAMP DMP ---------------------------------- -------------------------------------------------------------------- 22.02.16 09:54:35,389132000 +01:00 Typ=188 Len=20: 224,7,2,22,8,54,35,0,224,174,49,23,1,0,5,0,0,0,0,0 1 rows selected.

SQL> select systimestamp, dump(systimestamp) dmp from dual SYSTIMESTAMP DMP ---------------------------------- -------------------------------------------------------------------- 22.02.16 09:54:35,389132000 Typ=188 Len=20: 224,7,2,22,8,54,35,0,224,174,49,23,0,0,3,0,0,0,0,0 1 rows selected.

Page 12: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsformate

• Default Datumsformat richtet sich nach NLS-Session Einstellung SQL> select * from nls_session_parameters; PARAMETER VALUE ------------------------------ ------------------------------------ NLS_LANGUAGE GERMAN NLS_TERRITORY GERMANY NLS_CURRENCY Γé¼ NLS_ISO_CURRENCY GERMANY NLS_NUMERIC_CHARACTERS ,. NLS_CALENDAR GREGORIAN NLS_DATE_FORMAT DD.MM.YYYY NLS_DATE_LANGUAGE GERMAN NLS_SORT GERMAN NLS_TIME_FORMAT HH24:MI:SSXFF NLS_TIMESTAMP_FORMAT DD.MM.RR HH24:MI:SSXFF NLS_TIME_TZ_FORMAT HH24:MI:SSXFF TZR NLS_TIMESTAMP_TZ_FORMAT DD.MM.RR HH24:MI:SSXFF TZR NLS_DUAL_CURRENCY Γé¼ NLS_COMP BINARY NLS_LENGTH_SEMANTICS BYTE NLS_NCHAR_CONV_EXCP FALSE

Page 13: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Default-Datumsformate sind abhängig von NLS

• Ohne Formatmaske zu arbeiten, ist gefährlich ...

• Andere Session, andere NLS-Settings ...?

SQL> select to_date('22.02.2016') from dual; TO_DATE('22.02.2016') --------------------------- 22.02.2016 00:00:00 1 rows selected.

SQL> select to_date('22.02.2016') from dual; select to_date('22.02.2016') from dual * FEHLER in Zeile 1: ORA-01843: Kein gültiger Monat

Page 14: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Besser: Explizite Formate verwenden

• Explizite Formatmaske

• Aber ...

SQL> select to_date('22.02.2016', 'DD.MM.YYYY') DAT from dual; DAT --------------------------- 22.02.2016 00:00:00

SQL> select to_date('22-MAR-2016', 'DD-MON-YYYY') DAT from dual; select to_date('22-MAR-2016', 'DD-MON-YYYY') DAT from dual * FEHLER in Zeile 1: ORA-01843: Kein gültiger Monat

Page 15: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Besser: Explizite Formate verwenden

• Explizite Formatmaske und Datumssprache ...

• NLS_DATE_LANGUAGE ist wichtig für ...

– Vollständige und abgekürzte Monatsnamen

– Vollständige und abgekürzte Tagesnamen

– Erster Tag der Woche (bei uns: Montag, in USA: Sonntag)

SQL> select to_date('22-MAR-2016', 'DD-MON-YYYY', 'nls_date_language=''english''') DAT from dual; DAT --------------------------- 22.03.2016 00:00:00

Page 16: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

NLS-Unabhängige Datums-Literale: Ja, die gibt es auch!

• DATE-Literal nur für ein Datum ohne Uhrzeit

• TIMESTAMP-Literal

SQL> select DATE'2016-01-01' as DATE_INDEPENDENT_NLS from dual; DATE_INDEPENDENT_NLS --------------------------- 22.02.2016 00:00:00

SQL> select TIMESTAMP'2016-01-01 20:00:00.183 CET' as TS_INDEPENDENT_NLS from dual; TS_INDEPENDENT_NLS -------------------------------------- 01.01.16 20:00:00,183000000 CET

Page 17: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsarithmetik

• Klassische Arbeit mit DATE: Addition von Dezimalzahlen SQL> select sysdate, sysdate + 1 nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 22.02.2016 11:04:29 23.02.2016 11:04:29 SQL> select sysdate, sysdate - 1/48 nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 22.02.2016 11:04:34 22.02.2016 10:34:34 SQL> select sysdate, sysdate + 1/(24*60) nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 22.02.2016 11:04:57 22.02.2016 11:05:57

Auch mit TIMESTAMP möglich; dann aber

automatische Konvertierung

nach DATE

Page 18: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsarithmetik

• Arbeit mit INTERVAL-Datentyp SQL> select sysdate, sysdate + INTERVAL '1' DAY nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 22.02.2016 11:04:29 23.02.2016 11:04:29 SQL> select sysdate, sysdate + INTERVAL '30' MINUTE nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 22.02.2016 11:04:34 22.02.2016 10:34:34 SQL> select sysdate, sysdate + INTERVAL '1' MINUTE nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 22.02.2016 11:04:57 22.02.2016 11:05:57

Page 19: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsarithmetik mit INTERVAL-Datentypen

• Aufpassen mit dem MONTH-Interval am Ende eines Monats SQL> -- 28.01.2016 SQL> select sysdate, sysdate + INTERVAL '1' MONTH nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 28.01.2016 11:04:29 28.02.2016 11:04:29

Page 20: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsarithmetik mit INTERVAL-Datentypen

• Aufpassen mit dem MONTH-Interval am Ende eines Monats SQL> -- 28.01.2016 SQL> select sysdate, sysdate + INTERVAL '1' MONTH nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 28.01.2016 11:04:29 28.02.2016 11:04:29 SQL> -- 30.01.2016 SQL> select sysdate, sysdate + INTERVAL '1' MONTH nxt_date from dual;

Page 21: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsarithmetik mit INTERVAL-Datentypen

• Aufpassen mit dem MONTH-Interval am Ende eines Monats SQL> -- 28.01.2016 SQL> select sysdate, sysdate + INTERVAL '1' MONTH nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 28.01.2016 11:04:29 28.02.2016 11:04:29 SQL> -- 30.01.2016 SQL> select sysdate, sysdate + INTERVAL '1' MONTH nxt_date from dual; select sysdate, sysdate + INTERVAL '1' MONTH nxt_date from dual; * FEHLER in Zeile 1: ORA-01839: Datum für angegebenen Monat nicht gültig

Page 22: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsarithmetik mit INTERVAL-Datentypen

• ADD_MONTHS-Funktion berücksichtigt die Monatslängen SQL> -- 28.01.2016 SQL> select sysdate, sysdate + INTERVAL '1' MONTH nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 28.01.2016 11:04:29 28.02.2016 11:04:29 SQL> -- 30.01.2016 SQL> select sysdate, add_months(sysdate, 1) nxt_date from dual; SYSDATE NXT_DATE ------------------- ------------------- 30.01.2016 11:04:29 29.02.2016 11:04:29

Page 23: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsarithmetik: Subtraktion mit DATE

• Subtraktion mit DATE liefert Dezimalzahlen zurück. SQL> select DATE'2016-04-29' - DATE'2016-01-01' date_diff from dual; DATE_DIFF ---------------- 119 SQL> select to_date('2016-04-29 12:00', 'YYYY-MM-DD HH24:MI') – to_date('2016-04-27 08:30', 'YYYY-MM-DD HH24:MI') date_diff from dual; DATE_DIFF ---------------- 2,14583333

Page 24: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Datumsarithmetik: Subtraktion mit DATE

• Dezimalzahlen lassen sich umrechnen ...

• Zwei Intervalldatentypen

– Interval Day to Second

– Interval Year to Month

SQL> select numtodsinterval( to_date('2016-04-29 12:00', 'YYYY-MM-DD HH24:MI') – to_date('2016-04-27 08:30', 'YYYY-MM-DD HH24:MI'),' 'DAY' ) date_diff from dual; DATE_DIFF ----------------------------- +000000002 03:30:00.000000000

Page 25: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Einige Hilfsfunktionen für DATE und TIMESTAMP -1-

• TRUNC: Schneidet Teile des Datums ab – default: TRUNC 'DAY'

– TRUNC('2016-02-22 14:26', 'DAY') '2016-02-22 00:00'

– TRUNC('2016-02-22 14:26', 'HH') '2016-02-22 14:00'

• ROUND: Rundet ein Datum

– ROUND('2016-02-22 14:26', 'HH') '2016-02-22 14:00'

– ROUND('2016-02-22 14:36', 'HH') '2016-02-22 15:00'

• EXTRACT: Extrahiert Datumsteile

– EXTRACT(YEAR from DATE'2016-02-22') 2016

– EXTRACT(MONTH from DATE'2016-02-22') 2

Page 26: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Einige Hilfsfunktionen für DATE und TIMESTAMP -2-

• NEXT_DAY: Gibt das Datum des nächsten geforderten Wochentags zurück

– Achtung: NLS_DATE_LANGUAGE ist hier wichtig!

– NEXT_DAY(DATE'2016-02-23', 'DIE') '2016-03-01'

– NEXT_DAY(DATE'2016-02-23', to_char(DATE'2001-01-02','DAY'))

• LAST_DAY: Gibt des Monatsultimo zurück

– LAST_DAY (DATE'2016-02-16') '2016-02-29'

– LAST_DAY (DATE'2016-01-16') '2016-01-31'

Das ist ein Dienstag

Page 27: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

PL/SQL Challenge – schon gespielt?

http://plsqlchallenge.oracle.com

Page 28: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Oracle Developer Monthly – ab sofort on Demand

http://tinyurl.com/oradevmonthly

Page 29: Oracle Developer Monthly

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Nächster Oracle Developer Monthly

Ausgabe 03/2016 erscheint Ende März 2016

Nächster Oracle Database Monthly

2. März 2016 – 14:00 Uhr

Fragen und Diskussionen auf Twitter

#oradevmonthly

http://tinyurl.com/oradevmonthly http://tinyurl.com/oradbamonthly


Top Related