Skip to content

Instantly share code, notes, and snippets.

@Rizwan-Hasan
Last active October 7, 2019 12:06
Show Gist options
  • Save Rizwan-Hasan/89c3cce44357a3b8fe6e3822b72aa4fa to your computer and use it in GitHub Desktop.
Save Rizwan-Hasan/89c3cce44357a3b8fe6e3822b72aa4fa to your computer and use it in GitHub Desktop.
import cx_Oracle
def main():
# Variables
username: str = "HR"
password: str = "<YOUR_PASSWORD>"
host: str = "localhost"
service: str = "XE"
# Connection establishing
connection = None
try:
connection = cx_Oracle.connect(
username,
password,
"{0}/{1}".format(host, service)
)
print("Connection successful")
except cx_Oracle.DatabaseError as e:
print(e)
# Executing DDL
minSalary: int = 15000
maxManagerID: int = 200
cursor = connection.cursor()
cursor.execute(
"""SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES
WHERE SALARY > :sal AND MANAGER_ID < :man""",
sal=minSalary, man=maxManagerID
)
# Printing output
for fname, lname in cursor:
print("{0} {1}".format(fname, lname))
connection.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment