Python for Oracle. Oracle Database Great for Data Store. Critical for Business Operations. Performance? Run in laptop? But how do you share it?

Similar documents
Microservices using Python and Oracle. Arup Nanda Longtime Oracle DBA And Explorer of New Things

Twitter and While Loops. April

Networking for the Cloud DBA. Arup Nanda Longtime Oracle DBA And Explorer of New Things

ARTIFICIAL INTELLIGENCE AND PYTHON

LECTURE 21. Database Interfaces

Location Agnostic Data

Data Engineering for Data Science

Arup Nanda VP, Data Services Priceline.com

CME 193: Introduction to Scientific Python Lecture 1: Introduction

SQL Server Machine Learning Marek Chmel & Vladimir Muzny

Introduction to Python Part 2

CIS 192: Lecture 11 Databases (SQLite3)

Should You Drop Indexes on Exadata?

Webgurukul Programming Language Course

JatinSir - Mastering Python

Using Python with ArcGIS

Using SQLite in ArcGIS Python Scripts

ORACLE TRAINING CURRICULUM. Relational Databases and Relational Database Management Systems

Python Certification Training

Data Analytics Job Guarantee Program

Scientific Computing using Python

LABORATORY OF DATA SCIENCE. Data Access: Relational Data Bases. Data Science and Business Informatics Degree

Weekly Discussion Sections & Readings

Programming with Python with Software Automation & Data Analytics

Python Training. Complete Practical & Real-time Trainings. A Unit of SequelGate Innovative Technologies Pvt. Ltd.

Cosmology with python: Beginner to Advanced in one week. Tiago Batalha de Castro

Accessing Web Files in Python

Command Line and Python Introduction. Jennifer Helsby, Eric Potash Computation for Public Policy Lecture 2: January 7, 2016

RAC for Beginners. Arup Nanda Longtime Oracle DBA (and a beginner, always)

Arup Nanda Longtime Oracle DBA (and now DMA)

Exadata for Oracle DBAs. Arup Nanda Longtime Oracle DBA (and now DMA)

ENGR 102 Engineering Lab I - Computation

Databases. Course October 23, 2018 Carsten Witt

(Ca...

Matplotlib Python Plotting

Python Basics. Lecture and Lab 5 Day Course. Python Basics

Scientific Python. 1 of 10 23/11/ :00

LABORATORY OF DATA SCIENCE. Data Access: Relational Data Bases. Data Science and Business Informatics Degree

Resolving Latch Contention

Oracle EXAM - 1Z Oracle Database 11g: Performance Tuning. Buy Full Product.

Using SQL Developer. Oracle University and Egabi Solutions use only

Python Basics. Nakul Gopalan With help from Cam Allen-Lloyd

Installation Guide for Python

Oracle Database: SQL and PL/SQL Fundamentals

Introduction to Scientific Computing with Python, part two.

Privacy and Security in Online Social Networks Department of Computer Science and Engineering Indian Institute of Technology, Madras

RACifying Multitenant

Python for Earth Scientists

pymapd Documentation Release dev3+g4665ea7 Tom Augspurger

Certified Data Science with Python Professional VS-1442

Page 1. Oracle9i OLAP. Agenda. Mary Rehus Sales Consultant Patrick Larkin Vice President, Oracle Consulting. Oracle Corporation. Business Intelligence

Introduction to Data Science. Introduction to Data Science with Python. Python Basics: Basic Syntax, Data Structures. Python Concepts (Core)

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

Intermediate/Advanced Python. Michael Weinstein (Day 2)

MongoDB. Database Initialization. Note

Python for Data Analysis. Prof.Sushila Aghav-Palwe Assistant Professor MIT

Data Analytics Training Program using

Using Python with ArcGIS

CSE : Python Programming

Sunpy Python for Solar Physics Juan Carlos Martínez Oliveros

ERTH3021 Exploration and Mining Geophysics

Introduction to Python

Under the Hoods of Cache Fusion, GES, GRD and GCS

Manually Create Sql Profile Oracle 10g

Oracle 1Z0-054 Exam Questions and Answers (PDF) Oracle 1Z0-054 Exam Questions 1Z0-054 BrainDumps

Oracle PLSQL Training Syllabus

pandas: Rich Data Analysis Tools for Quant Finance

Application Express 4.0 Architecture & Configuration Marc Sewtz Senior Software Development Manager Oracle America Inc.

Data Acquisition and Processing

Python & Spark PTT18/19

The Art and Science of Tracing

Instituto Politécnico de Tomar. Python. Introduction. Ricardo Campos. Licenciatura ITM Técnicas Avançadas de Programação Abrantes, Portugal, 2018

Visualization of Large Dynamic Networks

Under the Hoods of Cache Fusion, GES, GRD and GCS

processing data with a database

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

Landscape Gardening AQA GCSE Computer Science Controlled Assessment

Latches Demystified. What is a Latch. Longtime Oracle DBA. Arup Nanda. From Glossary in Oracle Manuals:

Art and Craft of Tracing

Oracle Database 12c: Program with PL/SQL Duration: 5 Days Method: Instructor-Led

ADF Code Corner. 65. Active Data Service Sample Twitter Client. Abstract: twitter.com/adfcodecorner

Big Data Exercises. Fall 2016 Week 0 ETH Zurich

Scientific Computing with Python. Quick Introduction

How to Register for a Developer Account Nick V. Flor

PYTHON NUMPY TUTORIAL CIS 581

Manual Trigger Sql Server 2008 Examples Insert Update

Privacy and Security in Online Social Networks Department of Computer Science and Engineering Indian Institute of Technology, Madras

Programming in Python

Bridging the Gap. Peter Ebell AMIS

Oracle - Oracle Database: Program with PL/SQL Ed 2

Python. Department of Computer Science And Engineering. European University Cyprus

Lotus IT Hub. Module-1: Python Foundation (Mandatory)

Oracle Database: Program with PL/SQL

Python for Scientists

Scientific Computing: Lecture 1

Oracle Database: Program with PL/SQL Ed 2

Ch.1 Introduction. Why Machine Learning (ML)? manual designing of rules requires knowing how humans do it.

OracleMan Consulting

Session 1: Do's and Don'ts of Data Visualization. Presenter: Randy Olson, Ph.D.

About Intellipaat. About the Course. Why Take This Course?

Transcription:

Python for Oracle Arup Nanda Longtime Oracle Technologist And Python Explorer Oracle Database Great for Data Store Critical for Business Operations Performance? Run in laptop? But how do you share it? 2 1

What you will learn? Why Python How can you learn Python pretty fast, for Oracle Developers Plotting Charts Interaction with Oracle Tons of code, a free tutorial series on OTN, videos Three real-world example applications What s next 3 Why Python Used in data science, machine learning, AI Powerful and math plotting tools, free and paid Spark has a PySpark General purpose Not like R, which is very data oriented Convenience of Interpreted Language Rapid Application Development Default language of Raspberry Pi Has libraries for all types of access. Including Oracle DB. 4 2

Installation Python is freely available for most OS es Download from python.org For many platforms, even Rasperry Pi Three components: Command line version Command Line in a Window IDLE: Interactive DeveLopment Environment 5 Bring up command line From OS prompt: C:\> python (Same command executable on any of the OS es) Brings up the python command line prompt: Python prompt 6 3

How difficult is learning Python? It s similar not same as PL/SQL Some language elements are even the same Approach: Jumpstarting the learning by using examples of PL/SQL PL/SQL if Condition then statement end if; Python if Condition: statement 7 Help Me! Command help brings up the help interface >>> help() help> Command_You_Need_Help_On Or >>> help Command_You_Need_Help_On 8 4

Basics Python is case sensitive So, v1 and V1 are different. Comments Starts with # How to quit: It s a function. So, quit() Or Control-Z 9 Learning Tool 5 Part Article Series Complete tutorials Video Quizzes Free! bit.ly/python4plsql 10 5

Arrays Three types List x1 = [1,2,3] Can be any mix of datatypes [1, s,1.5] Address elements by x1[position] Tuple same as list but immutable x1 = (1,2,3) Dictionary key-value pairs x1 = {'k1':'v1','k2':'v2'} 11 If Python is positional if Condition: Statement elif Condition: Statement else: Statement This indentation is necessary 12 6

Looping FOR Loop for i in range(1,11): print('i=',i) Looping through arrays x1 = [ a, e, i, o, u ] for i in range(len(x1)): print(x1[i]) WHILE Loop 13 Adding Modules Python Package Index (PyPI) Install it my calling it as a module in python C:\> python -m pip ModuleName Modules we will install python -m pip pandas python -m pip numpy python -m pip matplotlib python m pip scipy 14 7

Data Analysis 15 Multi-dimensional Array Sales Data ProductID Quarter Territory Amount 16 8

2D Array Quarter 1 Quarter 2 Quarter 3 Quarter 4 Product 0 200 300 275 225 Product 1 400 600 550 450 Product 2 600 900 1000 500 Product 3 800 1200 1100 900 17 3D Array Territory 2 Quarter 1 Quarter 2 Quarter 3 Quarter 4 Product 0 200 300 275 225 Territory 1 Product 1Quarter 400 1 Quarter 600 2 Quarter 550 3 Quarter 450 4 Product Product 0 2200600 300900 2751000 225500 Product Product 1 3400800 6001200 5501100 450900 Product 2 600 900 1000 500 Product 3 800 1200 1100 900 18 9

19 Numpy Array sales = np.array([ [ [50,50,50,50], [150,150,180,120], [75,70,60,70], [55,45,65,55] ], [ [100,90,110,100], [150,160,130,170], [145,155,150,100], [110,115,105,120] ], [ ], [ ] ]) [150,140,160,150], [225,220,230,225], [250,200,300,250], [125,130,120,125] [200,250,150,200], [300,350,250,300], [225,230,220,225], [220,225,230,200] 20 10

sales.sum(axis=0) sales.min(axis=0) numpy1.txt 21 Visualization 22 11

Plotting Package matplotlib 23 Oracle DB Connection 24 12

Connecting to Oracle DB A module called cx_oracle Basic Operation >>> import cx_oracle as cxo >>> conn = cxo.connect( hr, hr, server:1521/al122') >>> c1 = conn.cursor() >>> c1.execute('select * from employees where rownum <11') >>> for row in c1:... print(row) Fetch one row alone r1 = c1.fetchone() Or, many r1 = c1.fetchmany(numrows=2) 25 More cx_oracle operations Set the arraysize >>> c1.arraysize = 10 Describe the output >>> c1.description One step fetch >>> r1 = c1.execute('select * from sales where rownum < 11') >>> for rec in r1:... print (rec) Close the cursor >>> c1.close() 26 13

Bind Variables >>> conn = cxo.connect('sh','sh','localhost:1521/al122') >>> c1 = conn.cursor() >>> c1.prepare('select * from sales where rownum < :limiting_rows') >>> c1.execute(none, {'limiting_rows':11}) >>> c1.fetchall() 27 Dynamically Constructed Queries Note the query c1.prepare('select * from...') You can construct the query as a character array >>> s1 = 'select ' >>> s1 += '*' >>> s1 += ' from sales ' >>> s1 += ' where rownum < ' >>> s1 += '11' >>> s1 'select * from sales where rownum < 11' >>> r1 = c1.execute(s1) 28 14

Example 1 29 Creating a DB Monitor Objective To measure waits on named events in database From AWR repository tables And plot them select sn.end_interval_time, (after.total_waits-before.total_waits) "No. of Waits", (after.time_waited_micro-before.time_waited_micro)/ (after.total_waits-before.total_waits) "Avg Wait in us" from dba_hist_system_event before, dba_hist_system_event after, dba_hist_snapshot sn where before.event_name=:event_name and after.event_name=before.event_name and after.snap_id=before.snap_id+1 and after.snap_id=sn.snap_id and (after.total_waits-before.total_waits) > 0 order by after.snap_id 30 15

Example 2 31 Finding Employee Retention Objective To model how employees stay in an organization Hypothesis The tenure of the employees depends on department, the specific job, the reporting manager. Methodology We will find the correlation between tenure and multiple other factors 32 16

Example 3 33 Twitter Analysis Objective To find out how many have been tweeting about Oracle Code (i.e. with #OracleCode), and how many times each has been retweeted. Store the data in an Oracle database for further processing Methodolgy A package called tweepy allows twitter interaction 34 17

Tweepy A package for accessing twitter accounts You need: Authentication details from twitter Consumer key Consumer secret Authentication token Authentication secret All can be gotten from https://dev.twitter.com/apps To Install tweepy Using command python m pip install tweepy 35 Authentication in Tweepy Define the values ckey = '...' csecret = '...' atoken = '...' asecret = '...' Authenticate auth = tweepy.oauthhandler(ckey,csecret) auth.set_access_token(atoken, asecret) Declare the API object api = tweepy.api(auth) 36 18

Accessing objects Details about the account >>> iam = api.me() To find out all about the account: for i in iam._json.keys(): print("%30s = %s" % (i, iam._json[i])) 37 Finding Tweets The search API is used >>> t = tweepy.cursor(api.search,q="#oraclecode",lang="en",since ="2018-03-01").items() We used the since parameter to limit the number of items The object t now contains the data on the tweets. To get the handle and text of the tweet: >>> for text in t:... print(text.author.screen_name, text.text) 38 19

More Uses Connecting to a physical device using Raspberry Pi Using a Event Driven Architecture to use fraud detection in transactions Using Oracle AQ and cx_oracle Using microservices where each service talks to another using messages 39 In Summary Python is a general purpose language; not just data Interpreted, but can also be cached Rich data manipulation capabilities exist natively as well as via packages Very easy to learn for Oracle PL/SQL developers Multiple use cases spanning a variety of applications 40 20

Thank You! Blog: arup.blogspot.com Tweeter: @ArupNanda Facebook.com/ArupKNanda Google Plus: +ArupNanda 41 21