We have moved to www.dataGenX.net, Keep Learning with us.

Monday, January 02, 2012

How to select last line in a table without CURSOR in DB2

Cursors will be used in DB2 SQL PL stored procedures to perform a complex logic on a row-by-row basis. There are four basic SQL PL statements for working with cursors:
- the DECLARE CURSOR statement to define a cursor
- the OPEN statement to adjust the cursor
- the FETCH statement to retrieve the next row of the cursor
- the CLOSE statement to deactivate the cursor
we can find out last row using cursor with some logic but we can do it without cursor also by using following logic...

db2 "select * from schema_name.table_name order by column_name desc fetch first 1 rows only "

Enjoy The simplicity...





No comments :

Post a Comment