2011年3月5日 星期六

MySQL 資料型態的限制



CHAR固定長度 0 到 255 字
VARCHAR變動長度 0 到 255 字
TINYTEXT255 字
TEXT,BLOB64Kib 字
MEDIUMTEXT,MEDIUMBLOB16Mib 字
LONGTEXT,LONGBLOB4Gib 字
TINYINT-128 to 127 或 0 to 255無符號
SMALLINT-32768 to 32767 或 0 to 65535無符號
MEDIUMINT-8388608 to 8388607 或 0 to 16777215無符號
INT-2147483648 to 2147483647 或 0 to 4294967295無符號
BIGINT-9223372036854775808 to 9223372036854775807 normal
FLOATA small number with a floating decimal point.
DOUBLEA large number with a floating decimal point.
DECIMALA DOUBLE stored as a string , allowing for a fixed decimal point.
DATEYYYY-MM-DD.
DATETIMEYYYY-MM-DD HH:MM:SS.
TIMESTAMPYYYYMMDDHHMMSS.
TIMEHH:MM:SS.
ENUM Short for ENUMERATION which means that each column may have one of a specified possible values.
SETSimilar to ENUM except each column may have more than one of the specified possible values.

MYSQL strip_tags

這是從MySQL官方上看到的資料,因為最近剛好有這個需求。

可以省下寫程式的時間,相當方便!!


delimiter ||
DROP FUNCTION IF EXISTS strip_tags||
CREATE FUNCTION strip_tags( x longtext) RETURNS longtext
LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA
BEGIN
DECLARE sstart INT UNSIGNED;
DECLARE ends INT UNSIGNED;
SET sstart = LOCATE('<', x, 1);
REPEAT
SET ends = LOCATE('>', x, sstart);
SET x = CONCAT(SUBSTRING( x, 1 ,sstart -1) ,SUBSTRING(x, ends +1 )) ;
SET sstart = LOCATE('<', x, 1);
UNTIL sstart < 1 END REPEAT;
return x;
END;
||
delimiter ;