标签:模版 pre mil mysq white 删除 uid string set
CREATE [AGGREGATE] FUNCTION function_name(parameter_name type,[parameter_name type,...])
RETURNS {STRING|INTEGER|REAL}
runtime_body
CREATE FUNCTION simpleFun() RETURNS VARCHAR(20)
BEGIN
RETURN "Hello World!";
end;
select simpleFun();
CREATE TABLE son (
id INT NOT NULL,
name VARCHAR(20),
pay INTEGER
);
INSERT INTO son (id, name, pay) VALUES (1,‘bol‘,20);
INSERT INTO son (id, name, pay) VALUES (2,‘davie‘,2220);
SELECT * FROM son;
DROP FUNCTION IF EXISTS deleteById;
CREATE FUNCTION deleteById(uid SMALLINT UNSIGNED)
RETURNS VARCHAR(20)
BEGIN
DELETE FROM son WHERE id = uid;
RETURN (SELECT COUNT(id) FROM son);
END
select deleteById(2);
DELIMITER $$
DROP FUNCTION IF EXISTS `test`;
CREATE FUNCTION `test`(gdate datetime) RETURNS varchar(255)
BEGIN
DECLARE x VARCHAR(255) DEFAULT ‘‘;
SET x= date_format(gdate,‘%Y%m%d%h%i%s‘);
RETURN x;
END $$
DELIMITER ;
SELECT test(‘2009-06-23 00:00:00‘)
DELIMITER $$
DROP FUNCTION IF EXISTS cutString ;
CREATE FUNCTION cutString(s VARCHAR(255),n INT) RETURNS varchar(255)
BEGIN
IF(ISNULL(s)) THEN RETURN ‘‘;
ELSEIF
CHAR_LENGTH(s)<n THEN- RETURN s;
ELSEIF
CHAR_LENGTH(S)=n THEN- RETURN ‘相等‘;
ELSE
RETURN CONCAT(LEFT(s,n),‘...‘);
END IF;
END $$
DELIMITER ;
SELECT cutString(‘323432234‘,4);
标签:模版 pre mil mysq white 删除 uid string set
原文地址:http://www.cnblogs.com/xujintao/p/7041016.html