Computer Science, asked by shivangiraj66, 7 months ago

Differentiate between fetchone() and fetchall() methods with suitable

examples for each. ​

Answers

Answered by Aadya8557
6

Explanation:

✓✓fetchall()

fetches all the rows of a query result. An empty list is returned if there is no record to fetch the cursor.

✓✓fetchone() method

returns one row or a single record at a time. It will return None if no more rows / records are available.

Answered by barnadutta2015
0

Answer: Data is displayed using the fetchone() and fetchall() methods of the Python MySQL connection. The use of MySQL databases by Python programmes is made possible thanks to this connection.

Explanation:

  • fetchall(): A list of tuples is produced by the procedure, which retrieves all (or all remaining) rows from a query result set. If there are no more rows available, an empty list is returned.

       Example: fetchall()

       query="select * from emp"

       mycur.execute(query)

       rows = mycur. fetchall() :

       for row in rows;

       print("Name :",row[1])

       print("Department :",row[2])

       print("Salary :", row[3])

  • fetchone(): This function gets the subsequent row from a result set of a query and returns a single sequence, or none if there are no additional rows. By default, the returned tuple is made up of data that has been transformed into Python objects and returned by the MySQL server.
    Example : fetchone()
    eno = int(input("Enter employee Number :"))
    query="select * from emp ; empno= {}". format(eno)
    mycur.execute(query)

        row = mycur.fetchene()

         if row!=None:

         print("Name :",row[1])

         print("Department :",row[2])

         print("Salary :",row[3])

         else:

         print("'nEmployee Number not found")

To know more, click here:

https://brainly.in/question/21067977

https://brainly.in/question/9171713

#SPJ3

Similar questions