Python For Oracle DBA
Python For Oracle DBA
Oracle DBAs
- This beginner-friendly Python lecture will take you from zero to programming in Python.
"Opinions expressed are solely my own and do not express the views or opinions of my
employer."
5
© 2020 EPICO TECH
What to expect from this
presentation and the reasons behind
it:
6
© 2020 EPICO TECH
https://www.oracle.com/a/ocom/docs/applications/50704-oracle-strategic-dba-checklist.pdf
7
8
© 2020 EPICO TECH
9
© 2020 EPICO TECH
- What is Python Programming Language?
- Python is an interpreted, high-level, general-purpose programming language ;
- Guido van Rossum is the creator and the first released of Python was in 1991;
- Open Source
- Comments #
- Similar PL/SQL but not the same. It's a plus if you already know PL/SQL.
© 2020 EPICO TECH
- What is Python Programming Language?
Basics concepts:
1 - Types :
1.2 FLOAT :
- Real numbers: E.g 12.21
- Float can be an integer
1.3 STRINGS:
Description = "SKI IS BLUE"
1.4 BOOLEAN:
True (T) - 1
False (F) - 0
Example: 5+10=15
-
Variables
Tuples
numbers=(0,23,5,6,7,2,4,24)
- Tuples are immutable.
Lists
Dictionaries
{"key01":1,"key02":"02","key03":[3,3,3],"key04":(4,4,4),"key05":5}
Sets
Functions
27
© 2020 EPICO TECH
- What can you do with Python?
- Install in Oracle Linux 7
- Documentation: http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/index.html
28
© 2020 EPICO TECH
What can you do with Python?
- Know the Python version in your system:
- Python on Oracle Linux 6.10
29
© 2020 EPICO TECH
- What can you do with Python?
1 - Connect to the Oracle Database.
1.1 - cx_Oracle x Installation :
- Documentation: https://cx-oracle.readthedocs.io/en/latest/
30
© 2020 EPICO TECH
- What can you do with Python?
- cx_Oracle x Installation – Pre-requisites:
• Install python version 3;
...
...
Dependency Installed:
python3-libs.x86_64 0:3.6.8-13.0.1.el7 python3-pip.noarch 0:9.0.3-7.el7_8 python3-setuptools.noarch
0:39.2.0-10.el7
Complete! 31
oraclelinux7]#
© 2020 EPICO TECH
- What can you do with Python?
- cx_Oracle x Installation – Pre-requisites:
32
© 2020 EPICO TECH
- What can you do with Python?
- cx_Oracle x Installation – Pre-requisites:
• Install Oracle Instant Client:
34
© 2020 EPICO TECH
- What can you do with Python?
1 - Connect to the Oracle Database.
1.2 - Install the Oracle Database software (Example of a 12Cr1 Oracle Database software installed
in a Oracle Linux 7.6):
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
INSTANCE_NAME STATUS
---------------- ------------
35
pythondb OPEN
© 2020 EPICO TECH
- What can you do with Python?
1 - Connect to the Oracle Database.
1.3 - Create the script to connect to the Oracle Database (Script called myconnectdb.py):
oraclelinux7]$ cat myconnectdb.py
from __future__ import print_function
import cx_Oracle
# Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer.
connection = cx_Oracle.connect("c##brunors", "112233", "localhost.localdomain/pythondb.localdomain")
cursor = connection.cursor()
cursor.execute(
'SELECT count(*) from all_users')
for value in cursor:
print("Values:", value)
36
© 2020 EPICO TECH
- What can you do with Python?
2 - E.g Comparing files to be used by an Oracle External tables :
2.1 File:
File techtable1.txt:
oraclelinux7]$ cat techtable1.txt
BRZ,Brazil,Portuguese
NEZ,New Zealand,English
PRT,Portugal,Portuguese
SPN,Spain,Spanish
File techtable2.txt:
37
© 2020 EPICO TECH
- What can you do with Python?
2 - E.g Comparing files to be used by an Oracle External tables :
40
© 2020 EPICO TECH
- What can you do with Python?
4- Python and OCI (Oracle Cloud Infrastructure ):
4.2 - Oracle Application Container Cloud Service :
https://docs.oracle.com/en/cloud/paas/app-container-cloud/index.html
41
© 2020 EPICO TECH
- What can you do with Python?
4- Python and OCI (Oracle Cloud Infrastructure ):
4.2 - Oracle Application Container Cloud Service : Deploy a Python Application to Oracle Cloud
3- Steps:
42
© 2020 EPICO TECH
43
© 2020 EPICO TECH
- Python and Oracle DBA career?
- Oracle Database Administrator L3
role
44
© 2020 EPICO TECH
- Python and Oracle DBA career?
- Oracle DBA role
45
© 2020 EPICO TECH
- Python and Oracle DBA career?
- Oracle Database Administrator
46
© 2020 EPICO TECH
Beginner-friendly Python for Oracle Techies
47
© 2020 EPICO TECH
Beginner-friendly Python for Oracle Techies
E-mail: [email protected]
49
© 2020 EPICO TECH