Monday 29 July 2013

What are pseudo columns?

A pseudocolumn behaves like a table column, but is not actually stored in the table. You can select from pseudocolumns, but you cannot insert, update, or delete their values.

CURRVAL: returns the current value of a sequence.

NEXTVAL: increments the sequence and returns the next value.

You must qualify CURRVAL and NEXTVAL with the name of the sequence:
sequence.CURRVAL
sequence.NEXTVAL

LEVEL: For each row returned by a hierarchical query, the LEVEL pseudocolumn returns 1 for a root node, 2 for a child of a root, and soon. A root node is the highest node within an inverted tree. A child node is any non–root node. A parent node is any node that has children. A leaf node is any node without children.

ROWID: For each row in the database, the ROWID pseudo column returns a row’s address. ROWID values contain information necessary to locate a row:
·         which data block in the data file
·         which row in the data block (first row is 0)
·         which data file (first file is 1)

ROWNUM: For each row returned by a query, the ROWNUM pseudo column returns a number indicating the order in which Oracle7 selects the row from a table or set of joined rows. The first row selected has a
ROWNUM of 1, the second has 2, and so on.

You can use ROWNUM to limit the number of rows returned by a query, as in this example:
SELECT *
FROM emp
WHERE ROWNUM < 10

SYSDATE: Return the system date.

No comments:

Post a Comment