...
Code Block |
---|
|
"""Example of a select query to an Oracle Database"""
import cx_Oracle
# Establish the database connection
dbh = cx_Oracle.connect(user='AIS_RPC',
password='********',
dsn="hydra2"
)
# Obtain a cursor and execute query
num_N_SUBJECT_ID = 100
cursorwith = dbh.cursor() as cursor:
cursor.execute("""
SELECT VC_SUBJ_TYPE_NAME, VC_CODE
FROM SI_V_SUBJECTS
WHERE N_SUBJECT_ID = :num_N_SUBJECT_ID
""", [num_N_SUBJECT_ID])
# Fetch column names and data as an associative array
columns = [i[0] for i in cursor.description]
data = [dict(zip(columns, row)) for row in cursor.fetchall()]
print(data)
# Print data
for row in data:
print(f"VC_SUBJ_TYPE_NAME: {row['VC_SUBJ_TYPE_NAME']}")
print(f"VC_CODE: {row['VC_CODE']}")
# Close the database connection
dbh.close()
|
PROCEDURE
Code Block |
---|
|
"""Example of a procedure call to an Oracle database"""
import cx_Oracle
# Establish the database connection
dbh = cx_Oracle.connect(user='AIS_RPC',
password='********',
dsn="hydra2"
)
# Obtain a cursor
cursorwith = dbh.cursor() as cursor:
# Prepare variables
num_N_SUBJECT_ID = cursor.var(cx_Oracle.NUMBER)
# Call procedure
cursor.execute("""
BEGIN
SI_PERSONS_PKG.SI_PERSONS_PUT(
num_N_FIRM_ID => 100,
num_N_SUBJECT_ID => :num_N_SUBJECT_ID,
vch_VC_SURNAME => 'Ivanov',
vch_VC_FIRST_NAME => 'Ivan',
vch_VC_SECOND_NAME => 'Ivanovich'
);
END;
""", num_N_SUBJECT_ID=num_N_SUBJECT_ID)
# Print value of a created basic subject
print(f"Created basic subject {num_N_SUBJECT_ID.getvalue()}")
# Commit changes
dbh.commit() # Close the database connection
dbh.closecommit()
|
PHP
Работа с СУБД выполняется с использованием OCI8
...