December 17th, 2008

POSITION (start pos. of a string)

The POSITION function returns an integer indicating the first starting position of a string within the search string.
If the search string is not found, zero will be returned.
Format: POSITION(search_string IN full_string)

Example:           POSITION('CADAB' IN 'ABRAH CADABRAH') Result: 7
                   POSITION('CABAD' IN 'ABRAH CADABRAH') Result: 0

> Various RDBMS systems are case sensitive or case insensitive. See the documentation for your system.

> Access uses InStr(start_position, string, substring) to find the beginning and InStrRev() to find the ending count from the end.

> DB2 uses POSSTR(string, substring).

> MySQL supports POSITION.

> Oracle uses INSTR(string, substring).

> SQL Server uses CHARINDEX(substring, string).
SQL Server also uses PATINDEX which allows wildcard characters.

December 16th, 2008

OCTET_LENGTH (bit length / 8)

The OCTET_LENGTH function returns the number of octets (8 bits) within the string expression.
Format: OCTET_LENGTH(string)

Example:           SELECT CUST_NAME,
                          OCTET_LENGTH(CUST_NAME) AS 'OCTET_LENGTH'
                     FROM CUSTOMER_TBL;

Result:

                   

> The length of an empty string (‘ ‘) is zero.
> Access, DB2, MySQL, Oracle, PostgreSQL, and SQL Server do not support OCTET_LENGTH.
> Access uses LEN(string) to find the number of characters.
> DB2 and Oracle use LENGTH(string) to find the number of characters.
> SQL Server uses DATALENGTH(string) to find the number of characters.
> MySQL uses BIT_COUNT(string) to find the number of bits.
> Oracle uses LENGTHB(string) to find the number of bits.

December 15th, 2008

MOD (division remainder)

The MOD function returns the remainder of a dividend divided by a divisor.
Format:                        MOD(dividend, divisor)

Example:           SELECT MOD(10, 7) FROM TABLEA;

Result:

                   

> Access, DB2, MySQL, PostgreSQL, SQL Server, and Sybase support the MOD function.

« Previous PageNext Page »