|
| 1 | +#------------------------------------------------------------------------------ |
| 2 | +# Query.py |
| 3 | +# |
| 4 | +# Demonstrate how to perform a query of a database schema, configured with Oracle's sample HR Schema, in your Exadata Express |
| 5 | +# Cloud Service. |
| 6 | +# |
| 7 | +# Before running this app: |
| 8 | +# 1. From the Exadata Express Cloud Service Console, click on Develop, then click on Python. Follow displayed instructions to: |
| 9 | +# - Install instant client. |
| 10 | +# - Enable client access and download your Exadata Express Cloud Service credentials. |
| 11 | +# - Install the Python Extension module (cx_Oracle) to enable access to your cloud service. |
| 12 | +# 2. Create a schema using the Exadata Express Cloud Service Console. Remember the schema name and password for step 4. |
| 13 | +# 3. Configure the schema with Oracle's Sample HR Schema. Scripts to configure this schema can be found on GitHub. |
| 14 | +# See github.com/oracle/db-sample-schemas for scripts and instructions. |
| 15 | +# 4. Modify cx_Oracle.connect to connect to the HR schema you created in step 2: |
| 16 | +# - The first value is the name of your HR schema. |
| 17 | +# - The second value is the password for your HR schema. |
| 18 | +# - The third value is "dbaccess", which is defined in the wallet downloaded from the Exadata Express Cloud Service |
| 19 | +#------------------------------------------------------------------------------ |
| 20 | + |
| 21 | +from __future__ import print_function |
| 22 | + |
| 23 | +import cx_Oracle |
| 24 | + |
| 25 | + |
| 26 | +connection = cx_Oracle.connect('HR',password,'dbaccess') |
| 27 | + |
| 28 | +sql = """ |
| 29 | +select * from employees where department_id = 90""" |
| 30 | + |
| 31 | + |
| 32 | +print("Get all rows via iterator") |
| 33 | +cursor = connection.cursor() |
| 34 | +for result in cursor.execute(sql): |
| 35 | + print(result) |
| 36 | +print() |
| 37 | + |
0 commit comments