Andy Todd wrote: > python eager wrote: >> Hi , This is my statment which will work fine. but the statment line is >> long. How to split up these lines . >> >> *Code Snippet :* >> >> for PID,FIRSTNAME,MIDDLENAME,LASTNAME, >> MARITALSTATUS,EMPLOYEESTATUS,NOD,SALARY, >> POI,RADDRESS,OADDRESS,MNO,LNO,DOBD,DOBM, >> DOBY,DOID,DOIM,DOIY,DOED,DOEM,DOEY in cursor.fetchall(): >> >> Please help me >> >> regards >> Python Eager >> >> >> _______________________________________________ >> DB-SIG maillist - DB-SIG@python.org >> http://mail.python.org/mailman/listinfo/db-sig > > The usual pattern is something like (untested, please ignore syntax errors); > > >>> myCursor.execute("SELECT x,y,z FROM tablea") > >>> for row in cursor.fetchall(): > ... print "Column x:", row[0] > ... print "y * z = %d" % (row[1] * row[2]) > > e.g. return each row of your results into a tuple and then reference the > individual elements by index. > > Sadly cx_Oracle doesn't offer different cursor classes like, for > instance, MySQLdb; > > http://dustman.net/andy/python/MySQLdb_obsolete/doc/MySQLdb-4.html#usage > > So you can't refer to cursor results as dictionaries or other sequence > types. > > Regards, > Andy
Of course, two minutes with Google offers up a couple of alternatives from the Python Cookbook. First, and along the sames lines as the solutions provided by Andy and Carsten we have this recipe; http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52293 Which I think is rather trumped by an alternative that uses Greg Stein's dtuple[1] module; http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81252 There's also a mention in the comments of the Opal Group's db_row module[2]. [1] http://www.lyra.org/greg/python/dtuple.py [2] http://opensource.theopalgroup.com/files/db_row.txt Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig