Get Age Using Mysql Functions
Get Age Using Mysql Functions:
· select (YEAR(CURRENT_DATE()) – YEAR(’2004-05-05′) –
(UNIX_TIMESTAMP(CURRENT_DATE())<UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE()),
‘-’, MONTH(’2004-01-02′), ‘-’, DAYOFMONTH(’2008-01-02′))))) AS `age`
· SELECT YEAR(DATE_SUB(NOW(), INTERVAL TO_DAYS(’2004-01-02′) DAY)) AS age
MySQL 5.x: passing limits as stored procedure / function parameters
MySQL 5.x (at least 5.0.15 and earlier versions) does not allow using variables or procedure formal parameters with LIMIT. Here is a workaround:
CREATE PROCEDURE sp (
IN LimitStart_ INT,
IN LimitCnt_ INT
)
BEGIN
SET @lim = CONCAT(‘ LIMIT ‘, LimitStart_, ‘,’, LimitCnt_);
SET @q = "SELECT mycol FROM mytable";
SET @q = CONCAT(@q, @lim);
PREPARE st FROM @q;
EXECUTE st;
DEALLOCATE PREPARE st;
END;
Got a packet bigger than ‘max_allowed_packet’ bytes mysql
set global max_allowed_packet=1000000000;
set global net_buffer_length=1000000;
set this from putty.
set-variable=record_buffer=16M
set this in my.cnf
Function to Convert given IP to Decimal
INET_ATON(expr)
Given the dotted-quad representation of a network address as a string, returns an integer that represents the numeric value of the address. Addresses may be 4- or 8-byte addresses.
mysql> SELECT INET_ATON('209.207.224.40');
-> 3520061480
The generated number is always in network byte order. For the example just shown, the number is calculated as 209×2563 + 207×2562 + 224×256 + 40.
INET_ATON() also understands short-form IP addresses:
mysql> SELECT INET_ATON('127.0.0.1'), INET_ATON('127.1');
-> 






















2130706433
, 






















2130706433

Note
When storing values generated by INET_ATON(), it is recommended that you use an INT UNSIGNED column. If you use a (signed) INT column, values corresponding to IP addresses for which the first octet is greater than 127 cannot be stored correctly. See Section 10.2, “Numeric Types”.
- To match a exact given IP range
- select * from Customer_IP where
INET_ATON(IP_End)>=INET_ATON(’203.188.65.0′) and INET_ATON(IP_Start)<=INET_ATON(’203.188.65.0′)
INET_NTOA(expr)
Given a numeric network address (4 or 8 byte), returns the dotted-quad representation of the address as a string.
mysql> SELECT INET_NTOA(3520061480);
-> '209.207.224.40′





