MySQL函数过程示例-删除和插入数据

阅读更多
[color=darkred][size=medium]
BEGIN
-- CALL P_DELETE_SERVICE_DATA('a','create_time','2015-12-23 15:00:00','2015-12-23 15:58:00');

--    -----------------------------delete template-------------------------------

SET @delete_data=CONCAT('delete from ',tableName ,' where ',fieldName,' between ','"',startTime,'"',' and ','"',endTime,'"');
   
prepare delete_talbe_data from @delete_data; 
execute delete_talbe_data; 
--    -----------------------------delete template-------------------------------


SET @array_content="www mysql com hcymysql blog 51cto com"; 
SET @i=1; 
SET @count=CHAR_LENGTH(@array_content)-CHAR_LENGTH(REPLACE(@array_content,' ','')) + 1; 
-- 得出数组成员总数 
CREATE TABLE b(field VARCHAR(100)); 
 
WHILE @i <= @count 
    DO 
    INSERT INTO b VALUES  (SUBSTRING_INDEX(SUBSTRING_INDEX(@array_content,' ',@i),' ',-1));      
    -- 依次插入每个成员  
    SET @i=@i+1; 
END WHILE; 


END
[/size][/color]

你可能感兴趣的:(mysql)