public static <T> String createSQLINClause(String colName, List<T> arr) {
final int MAX_IN_COUNT = 1000;
if (colName != null && arr != null && arr.size() > 0) {
String ret = "";
int to = (int) Math.ceil((double) arr.size() / MAX_IN_COUNT);
for (int i = 0; i < to; i++) {
int fromIndex = i * MAX_IN_COUNT;
int toIndex = (i + 1) * MAX_IN_COUNT;
List<T> subList = arr.subList(fromIndex, toIndex > arr.size() ? arr.size() : toIndex);
ret += colName + " IN (" + join(subList, ", ") + " ) ";
if (i < to - 1)
ret += " OR ";
}
return " ( " + ret + " ) ";
} else
return "";
}
Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts
15 July 2012
Code to group each 1000 entry in one IN Cluase
Here's an implmenetaion in Java for http://stackoverflow.com/questions/2401066/oracle-sql-how-to-use-more-than-1000-items-inside-an-in-clause#2401090
12 March 2012
Difference between CHAR and NCHAR in Oracle
I'd like to share you with some piece of info I found while searching about the difference between CHAR and NCHAR in Oracle and why Oracle DB has two Charsets
This info I got from SO here. and Here's it:
This info I got from SO here. and Here's it:
The NVARCHAR2 datatype was introduced by Oracle for databases that want to use Unicode for some columns while keeping another character set for the rest of the database (which uses VARCHAR2). The NVARCHAR2 is a Unicode-only datatype.
One reason you want to use NVARHCAR2 might be that your DB uses a non-Unicode character and you still want to be able to store Unicode data for some columns. Another reason might be that you want to use two Unicode character set (AL32UTF8 for data that comes mostly from western Europe, AL16UTF16 for data that comes mostly from Asia for example) because different character sets won't store the same data equally efficiently.
Both columns in your example (Unicode VARCHAR2(10 CHAR) and NVARCHAR2(10)) would be able to store the same data, however the byte storage will be different. Some strings may be stored more efficiently in one or the other.
Note also that some features won't work with NVARCHAR2, see this SO question:
Oracle Text will not work with NVARCHAR2. What else might be unavailable?

30 January 2012
Paging in Oracle
To do paging in oracle, the best way is to use:
Source: http://stackoverflow.com/questions/241622/paging-with-oracle#241643
SELECT * FROM
(
SELECT a.*, rownum r__
FROM
(
SELECT * FROM ORDERS WHERE CustomerID LIKE 'A%'
ORDER BY OrderDate DESC, ShippingDate DESC
) a
WHERE rownum < ((pageNumber * pageSize) + 1 )
)
WHERE r__ >= (((pageNumber-1) * pageSize) + 1)
Source: http://stackoverflow.com/questions/241622/paging-with-oracle#241643
Subscribe to:
Posts (Atom)