Posts

Showing posts from July, 2021

How to Update and Delete Records from Oracle Database Table using Python?

Image
This post is part of a series of blog posts on basic CRUD operations in Oracle Database using python. CRUD operations in Oracle Database using Python How to Create Records into Oracle Database Table using Python? How to Read Records from Oracle Database Table using Python? How to Update and Delete Records from Oracle Database Table using Python? This is the fourth and final post of this series. In this post, let's understand the 'U' and 'D' of the CRUD operations, which is how to Update and Delete records from a database table. Update Records We already know how to insert and fetch the records from the table and now updating the records is easy for us. Let's I want to update the salary and commission of an employee Martin into our EMP_TEST table. #Update statement sql_stmt = """ UPDATE EMP_TEST SET SAL =:1, COMM = :2 WHERE EMPNO = :3

How to Read Records from Oracle Database Table using Python?

Image
This post is part of a series of blog posts on basic CRUD operations in Oracle Database using python. CRUD operations in Oracle Database using Python How to Create Records into Oracle Database Table using Python? How to Read Records from Oracle Database Table using Python? How to Update and Delete Records from Oracle Database Table using Python? This is the third post of this series. In the second post, we have already covered how to create records in the Oracle database table. In this post, let's understand the 'R' of the CRUD operations, which is how to read records from a database table. To read the records from the database, we use the Select query. After executing the Select statement, we have to fetch the records from the database. For this operation, we have three methods:  cursor.fetchone()         : Used to fetch only one-row cursor.fetchall()           : Used fetch all rows cursor.fetchmany(n)    : Used to fetch n number of rows Fetch Single Row To fetch the re

How to Create Records into Oracle Database Table using Python?

Image
This post is part of a series of blog posts on basic CRUD operations in Oracle Database using python. CRUD operations in Oracle Database using Python How to Create Records into Oracle Database Table using Python? How to Read Records from Oracle Database Table using Python? How to Update and Delete Records from Oracle Database Table using Python? This is the second post of this series. In the first post, I have explained the steps that we need to follow to connect with the Oracle database using cx_Oracle and also explained the basic methods that we will use to perform database operations. Now we know the basic steps that we need to follow, let's understand the 'C' of the CRUD operations, which is how to create records into a table. First, we need to create the connection as mentioned earlier.  import cx_Oracle as cx import db_config as db try: #create connection conn = cx.connect(db.username,db.password,db.connect_string) except Exception as err: print('

CRUD operations in Oracle Database using Python

Image
In my previous post , I explained how to connect to Oracle Database using Python. In this blog series, I will explain how to perform CRUD Operations using Python. CRUD operations in Oracle Database using Python How to Create Records into Oracle Database Table using Python? How to Read Records from Oracle Database Table using Python? How to Update and Delete Records from Oracle Database Table using Python? This is the first blog of the series, where I explain the basics of the cx_Oracle module.  I'll use the emp_test table for all the examples in this series. Create the table using the below script. CREATE TABLE EMP_TEST(EMPNO NUMBER(4,0) PRIMARY KEY, ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4,0), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), DEPTNO NUMBER(2,0)); To perform any acti