MySQL?洢??????????????
?????BuleSky ???????[ 2016/11/17 11:20:09 ] ????????MySQL ?????
????????洢?????????
?????洢??????????????????????洢????????е????SQL????????????洢????????????????????????????????????????????????÷???????????????????????????Ч?????к?????
?????洢??????????????????????????з?????????洢??????У??洢???????????????IN??OUT??INOUT?????????????????????IN??????????к???????????????????????MySQL??????????????????????????洢?????
??????????洢????????
?????????????????????????????ж???SQL?????????ЩSQL?????????????????????????????????仯???仯??????й????У???Щ??????????SQL??????н??????????к????SQL??????????????MySQL???????????????洢??????????
?????洢?????????????
????<1> ?洢??????????????????????????SQL?????????????????????????
????<2> ?洢??????????????????????????????????????
????<3> ?洢???????????????????????????????
?????洢?????????????
????<1> ?洢???????????д?????SQL??臨????????????и???????????????顣
????<2> ???д?洢????????????????????Щ?????????????
?????洢???????????????? ?????????洢??????????
?????????????洢?????????????????£?
????CREATE
????[DEFINER = { user | CURRENT_USER }]
????PROCEDURE sp_name ([proc_parameter[??...]])
????[characteristic ...] routine_body
????CREATE
????[DEFINER = { user | CURRENT_USER }]
????FUNCTION sp_name ([func_parameter[??...]])
????RETURNS type
????[characteristic ...] routine_body
????proc_parameter??[IN|OUT|INOUT]param_name type
????func_parameter:param_name type
????type:Any valid MySQL data type(???MySQL?е?????????????)
????????????
????CALL sp_name([parameter[??…]])
????MySQL??洢???????????????????DDL??????????洢?????????????Commit???????????????????????Rollback??????????????????????洢???????????в????????LOAD DATA INFILE????????洢?????????п???????????????????????
???????1???????????????????????????????????????????????????????д???“??”??????????????“÷”??β?????????????????洢???????????????????????????????
????mysql>DELIMITER $$
????->CREATE PROCEDURE emp_in_hire(IN emp_name_reg VARCHAR(10)??OUT emp_count INT)
????->READS SQL DATA
????->BEGIN
????->SELECT id FROM emp WHERE ename REGEXP emp_name_reg;
????->SELECT FOUND_ROWS() INTO emp_count;
????->END $$
????mysql>DELIMITER ;
????mysql>CALL emp_in_hire ('^??'??@emp_count);
????+----+
????| id |
????+----+
????| 2 |
????+----+
????1 row in set (0.00 sec)
????Query OK?? 1 row affected (0.00 sec)
????mysql>SELECT @emp_count;
????+------------+
????| @emp_count |
????+------------+
????| 1 |
????+------------+
????1 row in set (0.00 sec)
????????п??????????????????????????????????????????????????????????洢?????????????????????SQL????????????????????????ж?α?дSQL???
???????????????????????п?????????????£???IN????????emp_name_reg ??????????VARCHAR?????????????????????????MySQL5.6?汾?л???????????INT????????????????????????VARCHAR?????????????????????????????????????????????????
???????????????????????????????洢??????????????????????????????2??????????????????????????????????ж????ε??????????????????????????????е????????????
????DELIMITER $$
????CREATE PROCEDURE delete_one_emp(IN ename VARCHAR(10))
????BEGIN
????DELETE FROM EMP WHERE ename=ename;
????END $$
?????????????洢???????????’????’??????????????????????????????????к???????????????????????????????????д??????????Сд??????????MySQL???Сд????С?
???????2????????????????????????????????????????????????
????DELIMITER $$
????CREATE FUNCTION add_salary(raise_count int(5)??e_name_reg varchar(10))
????RETURNS int(10)
????COMMENT ’?????’
????BEGIN
????UPDATE EMP SET SALARY = SALARY+raise_count WHERE ENAME RLIKE e_name_reg;
????RETURN (SELECT max(SALARY) FROM EMP);
????END $$
????DELIMITER;
????SELECT add_salary(5000??'^??');
?????洢??????????CREATE??????????CREATEOR REPLACE??洢???????????????????????????е?洢???????????????????????ALTER????
??????洢???????????????????characteristic?????????????????????????????
????<1>LANGUAGE SQL?????????????BODY?????SQL?????д????????????????????SQL???????????????洢??????????
????<2>[NOT]DETERMINISTIC??DETERMINISTIC??????????????????????????????NOT DETERMINISTIC??????????????????????????????????????б??????????á?
????<3>{CONTAINS SQL|NOT SQL|READS SQL DATA|MODIFIES SQL DATA}????Щ???????????????????????????????Щ??????????????????????????и?????Щ??????????????????????????????CATAINS SQL????????????????д?????NOT SQL????????????SQL???READS SQL DATA??????????????????????????????д????????MODIFIES SQL DATA???????????д?????????????Щ?????????????????????????CONTAINS SQL??
????<4>SQL SECURITY{DEFINER|INVOKER}???????????????????????????????????????У?????????????????????С??????DEFINER??
????<5>COMMENT ???洢????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11