Unable to insert data in oracle sql using python

Viewed 20

I am trying to insert data into a table created in oracle sql using python. It temporarily inserts data into the table but as soon as the python process ends , the data is deleted.

def submit_button(roll_no,name,marks):
    sql_query = 'INSERT INTO assignment_7 VALUES (:r,:n,:m)'
    c.execute(sql_query,[int(roll_no),name,int(marks)])
    c.execute('SELECT * FROM assignment_7')
    for rows in c:
        print(rows[0],'-',rows[1],'-',rows[2])

For example if (12,'aryan',20) are inserted into the table , the print statement works , but actually no data gets inserted when I check the table itself .

Name Null? Type


ROLL_NO NOT NULL NUMBER STUDENT_NAME VARCHAR2(30) MARKS NUMBER

1 Answers

try to add c.commit

def submit_button(roll_no,name,marks):
    sql_query = 'INSERT INTO assignment_7 VALUES (:r,:n,:m)'
    c.execute(sql_query,[int(roll_no),name,int(marks)])
    c.commit
    c.execute('SELECT * FROM assignment_7')
    for rows in c:
        print(rows[0],'-',rows[1],'-',rows[2])
Related