The Oracle WIDTH_BUCKET function is used to construct equiwidth histograms, in which the histogram range is divided into intervals that have identical size. For a given expression, the WIDTH_BUCKET function returns the bucket number into which the value of this expression would fall after being evaluated.
WIDTH_BUCKET also creates (when needed) an underflow bucket numbered '0' and an overflow bucket numbered num_buckets+1. These buckets handle values less than min_value and more than max_value, and are helpful in checking the reasonableness or 'sanity' of endpoints.
The expression for which the histogram is being created. This expression must evaluate to a number or a datetime value. When expr evaluates to
NA, then the expression returns
An expression that resolves to the minimum end point of the acceptable range for expr. This expression must evaluate to number or datetime values, and cannot evaluate to
An expression that resolves to the maximum end point of the acceptable range for expr. This expression must evaluate to number or datetime values, and cannot evaluate to
An expression that resolves to a constant indicating the number of buckets. This expression must evaluate to a positive
WIDTH_BUCKET(<value>, <min_value>, <max_value>, <number_of_buckets>);
SELECT customer_id, cust_last_name, credit_limit,
WIDTH_BUCKET(credit_limit, 100, 4000, 10) CREDIT_GRP
WHERE nls_territory = 'SWITZERLAND'
ORDER BY credit_grp;