मराठी

Consider the following SQL table MEMBER in a SQL Database CLUB: Table: MEMBER M_ID M1001 M1002 M1003 M1004 M1005 NAME Amina Pratik Simon Rakesh Avneet ACTIVITY GYM GYM SWIMMING GYM SWIMMING - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Consider the following SQL table MEMBER in a SQL Database CLUB:

          Table: MEMBER

M_ID NAME ACTIVITY
M1001 Amina GYM
M1002 Pratik GYM
M1003 Simon SWIMMING
M1004 Rakesh GYM
M1005 Avneet SWIMMING

Assume that the required library for establishing the connection between Python and MYSQL is already imported in the given Python code. Also assume that DB is the name of the database connection for table MEMBER stored in the database CLUB.

Predict the output of the following code :

MYCUR = DB.cursor() 
MYCUR.execute ("USE CLUB") 
MYCUR.execute ("SELECT * FROM MEMBER WHERE ACTIVITY= 'GYM' ") 
R=MYCUR.fetchone() 
for i in range(2) :
      R=MYCUR.fetchone() 
      print (R[0], R[1], sep = "#")
लघु उत्तर

उत्तर

Output:

M1002#Pratik
M1004#Rakesh

Explanation: 

Because fetchone() may read a single row from a table, the following code will produce M1002#Pratik and M1004#Rakesh. The fetchone() function reads the first row from the database in the fourth line of the code. The cursor is then positioned after the first row, and the loop begins, ranging two lines from the table where the activity equals gym. As a result, the output will be M1002#Pratik and M1004#Rakesh since they are the only rows that meet the specified criterion, which is that activity equals gym.

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2021-2022 (April) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×