Skip to content

Categories:

Pagination with ROWNUM

select *
from ( select /*+ FIRST_ROWS(n) */
a.*, ROWNUM rnum
from ( your_query_goes_here,
with order by ) a
where ROWNUM <=
:MAX_ROW_TO_FETCH )
where rnum  >= :MIN_ROW_TO_FETCH;

where

  • FIRST_ROWS(N) tells the optimizer, “Hey, I’m interested in getting the first rows, and I’ll get N of them as fast as possible.”
  • :MAX_ROW_TO_FETCH is set to the last row of the result set to fetch—if you wanted rows 50 to 60 of the result set, you would set this to 60.
  • :MIN_ROW_TO_FETCH is set to the first row of the result set to fetch, so to get rows 50 to 60, you would set this to 50.

The concept behind this scenario is that an end user with a Web browser has done a search and is waiting for the results. It is imperative to return the first result page (and second page, and so on) as fast as possible. If you look at that query closely, you’ll notice that it incorporates a top-N query (get the first :MAX_ROW_TO_FETCH rows from your query) and hence benefits from the top-N query optimization I just described. Further, it returns over the network to the client only the specific rows of interest—it removes any leading rows from the result set that are not of interest.
Continued…


Java Random Numbers

Java provides one utility class called Random. This class mainly used to generate random numbers. This class is very much useful for an application that selects a winner randomly. This class can also be used to generate random passwords.

The below example will generate random number 10 times between 0 to 50

import java.util.Random;
public class RandomNumberExample {
  public static void main(String[] args) {
    Random randomNumber = new Random( System.currentTimeMillis() );
    for (int i = 0; i < 10; i++) {
      System.out.println(randomNumber.nextInt(50));
    }
  }
}

and below is example to generate random password.

import java.util.Random;
public class RandomPassword {
  public static void main(String[] args) {
    Random randomNumber = new Random();
    char password[] = new char[15];
    for (int i = 0; i < 15;) {
      int value = randomNumber.nextInt(125);
      if ((value >= 48 && value <= 57)
           || (value >= 65 && value <= 90)
           || (value >= 97 && value <= 122)) {
               password[i] = (char) value;
               i++;
      }
    }
    System.out.println("Your password is " + new String(password));
  }
}

Above example the word range will be 0-9, A-Z and a-z. Since we want the combination of this characters, we have put a condition where we are checking for the integer value to be in range of 48 – 57 or 65 – 90 or 97 – 122. These integer values represents the ASCII values for the above word range.

Please refer the ASCII chart.

You can modify the class for use in JSP.

Random randomNumber = new Random();
char password[] = new char[15];
for (int i = 0; i < 15;) {
    int value = randomNumber.nextInt(125);
       if ((value >= 48 && value <= 57)
           || (value >= 65 && value <= 90)
           || (value >= 97 && value <= 122)) {
                   password[i] = (char) value;
                   i++;
        }
}

Basic of CSS

1. The CSS Rule

The CSS rule consist of two main parts

  1. Selector
  2. Declaration

to understand about each part, please look at the example below.

h2 { color : red }

h2 is Selector
color : red is Declaration

with the example above, text color of the element <h2> is red.

Continued…