Python For The Oracle DBA: A Taste of What's Cooking at US Foods
Python For The Oracle DBA: A Taste of What's Cooking at US Foods
Python For The Oracle DBA: A Taste of What's Cooking at US Foods
Bobby Durrett
Why Python?
• Easy to use
• Connects to everything
2
Easy to use
3
Easy to use - Takes effort to learn
4
Easy to use - Easy to come back to
5
Hello World – C++
#include <iostream>
int main () {
std::cout << "Hello world!" << std::endl;
}
http://rosettacode.org/wiki/Hello_world/Text
6
Hello World – Java
http://rosettacode.org/wiki/Hello_world/Text
7
Hello World – Python
print("Hello world!")
http://rosettacode.org/wiki/Hello_world/Text
8
Easy to use - Great online documentation
• Tutorial also
9
Documentation Screenshot
10
Easy to use - Very active online forum
• Fast answers
11
Stack Overflow Screenshot
12
Easy to use - Features that make it easy to use
• Dynamic Typing
• Lists
• Indentation
13
Dynamic typing
>>> x=5
>>>
>>> type(x)
<class 'int'>
>>>
>>> x="Hello"
>>>
>>> type(x)
<class 'str'>
>>>
>>> x = [1,2,"Greetings"]
>>>
>>> type(x)
<class 'list'>
14
List type
>>> l=[1,2,3]
>>>
>>> l.append(4)
>>>
>>> l
[1, 2, 3, 4]
>>>
>>> l[2:4]
[3, 4]
>>>
>>> l[3]
4
15
Indentation
>>> x = 5
>>> if x > 0:
... print("Greater than zero")
... x = 0
...
Greater than zero
>>>
>>> if x == 0:
... print("Equals zero")
... x = 1
File "<stdin>", line 3
x = 1
^
IndentationError: unindent does not match any outer
indentation level
16
Easy to use – used for teaching
17
Connects to everything
• Databases
• Graphics
• Local programs
• Remote servers
• Cloud
https://www.python.org/doc/essays/blurb/
18
Connects to everything - Databases
• Oracle
• Snowflake
• MySQL
• Google BigQuery
19
Oracle Database
import cx_Oracle
con = cx_Oracle.connect('test/test@dbatest')
cur = con.cursor()
cur.close()
con.close()
20
Connects to everything - Graphics
• Matplotlib
• http://matplotlib.org/index.html
• PythonDBAGraphs
• https://github.com/bobbydurrett/PythonDBAGraphs
21
PythonDBAGraphs example
22
Connects to everything – local programs
• Subprocess module
• https://docs.python.org/3/library/subprocess.html
p = subprocess.Popen(['sqlplus','/nolog'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
23
Connects to everything – remote servers
• Ftplib - ftp
• https://docs.python.org/3/library/ftplib.html
• Paramiko – ssh
• http://www.paramiko.org/
24
Connects to everything - Cloud
import boto3
import botocore
s3 = boto3.resource('s3’)
mybucket='aws.xyz.bobby’
bucket = s3.Bucket(mybucket)
s3.meta.client.head_bucket(Bucket=mybucket)
s3.Object(mybucket,'Test/test3.csv’).put(
Body=open('test3.csv', 'rb'))
25
Conclusion
26
Contact Information
27