How to find last row and last column of table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zilani
    New Member
    • Apr 2007
    • 1

    How to find last row and last column of table?

    Hi all,

    I am new to thescripts. Please assist me.

    How to find lastrow and lastcolumn of a table in oracle?
  • masdi2t
    New Member
    • Jul 2006
    • 37

    #2
    Originally posted by zilani
    Hi all,

    I am new to thescripts. Please assist me.

    How to find lastrow and lastcolumn of a table in oracle?
    lastrow:

    SELECT * FROM your_table WHERE rownum=1 ORDER BY your_auto_incre ment_field DESC

    lastcolumn (i don't get it why you need this information). this is the last column's name, not column's data

    SELECT coumn_name FROM user_tab_cols WHERE table_name = your_table AND column_id = (SELECT max(column_id) FROM user_tab_cols WHERE table_name = your_table)

    Comment

    • dipakyadav
      New Member
      • Mar 2010
      • 3

      #3
      Simple as is works for me

      SELECT column_name FROM table_name WHERE rowid=(SELECT MAX(rowid) FROM table_name)

      Comment

      • magicwand
        New Member
        • Mar 2010
        • 41

        #4
        Well it depends a lot on how you define "last".

        Since - per definition - there is no ordering in a relational table, it is defined by your ORDER BY clause.

        so ORDER BY <your_criteri a> DESC and fetch the row with rownum = 1

        Comment

        Working...