Home > Programming > FIRST_VALUE

FIRST_VALUE


FIRST_VALUE merupakan fungsi Oracle untuk mendapatkan nilai pertama dari sebuah pengelompokkan yang urut, berikut merupakan definisi dari Oracle:

Definition:

The Oracle PL/SQL FIRST_VALUE function is an analytic function which selects the first record from the partitioned and ordered set of rows. You can specify the IGNORE NULLS parameter to ignore the NULL values of the operand column and force consideration of NOT NULL values.

If the first value in the result set is NULL then the function returns NULL unless you specify IGNORE NULLS.
If you use the IGNORE NULLS parameter then FIRST_VALUE will return the first non-null value found in the result set. (If all values are null then it will return NULL.)

Example Syntax:

FIRST_VALUE(expression [INGORE NULLS]) OVER (analytic_clause)

Note that you cannot nest analytic functions by using FIRST_VALUE for expression.

Example Usage:

The SQL query below shows the ‘Highest Salary’ of employees who are reporting to the same manager.

SELECT EMPNO, ENAME, SAL,
FIRST_VALUE (SAL IGNORE NULLS) OVER (PARTITION BY MGRNO ORDER BY SAL DESC) "Highest Salary"
FROM EMPLOYEES
Categories: Programming Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: