Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql中的存储过程_Mysql_Sql_Database_Phpmyadmin - Fatal编程技术网

mysql中的存储过程

mysql中的存储过程,mysql,sql,database,phpmyadmin,Mysql,Sql,Database,Phpmyadmin,此存储过程负责物料保留。其基本思想是,它检查有多少这种材料已经雇用,如果仍然有库存的材料,我将插入一个新的订单。如果已经有此预订id的此材料的预订,我将更新金额 也许我做错了什么,但当我尝试添加一个新的预订时,它就起作用了。更新永远不起作用,并且当已经有特定物料id的预订时,不可能使用其他预订id租用 我举一个例子: CALL aantal_besch_mat_van_tot('2007-03-13','2007-03-14',15,6,50,'procedure test lol'); 好的

此存储过程负责物料保留。其基本思想是,它检查有多少这种材料已经雇用,如果仍然有库存的材料,我将插入一个新的订单。如果已经有此预订id的此材料的预订,我将更新金额

也许我做错了什么,但当我尝试添加一个新的预订时,它就起作用了。更新永远不起作用,并且当已经有特定物料id的预订时,不可能使用其他预订id租用

我举一个例子:

CALL aantal_besch_mat_van_tot('2007-03-13','2007-03-14',15,6,50,'procedure test lol');
好的,这是可行的,但当我再次执行它时,数量50应该变为50+上一个,所以它应该是100,它永远不会更新

此外,当你用另一个预订id租用同一材料时,它也不起作用。 例如:

这也是行不通的

我已经打印出了所有的价值,并且得到了正确的金额

在这里您可以找到我的存储过程代码:

    DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `fabiola`.`aantal_besch_mat_van_tot`(IN `p_datum_van` date,IN `p_datum_tot` date,IN `p_mat_id` int, IN `p_res_id` int, IN `p_nodig` int, IN `p_mat_opmerking` VARCHAR(255))

BEGIN
    DECLARE aantal INT DEFAULT 0;
    DECLARE tot  INT DEFAULT 0;
    DECLARE upda INT DEFAULT 0;
    DECLARE nieuwa INT DEFAULT 0;
    DECLARE voriga INT DEFAULT 0;
    DECLARE test INT DEFAULT 0;
    DECLARE res_van datetime;
    DECLARE res_tot datetime;

    -- Overeenkomstige data selecteren
    SELECT r.incheckdatum, r.uitcheckdatum FROM reservaties r
    WHERE r.id = p_res_id
    INTO res_van, res_tot;

        SELECT mpr.aantal FROM materialen_per_reservatie mpr
        WHERE mpr.materialen_id = p_mat_id AND
            (
            (p_datum_van >= mpr.datum_van AND p_datum_tot <= mpr.datum_tot) -- overlap: binnen
            OR (p_datum_van <= mpr.datum_van AND p_datum_tot >= mpr.datum_van) -- overlap: voor+in
            OR (p_datum_van <= mpr.datum_tot AND p_datum_tot >= mpr.datum_tot) -- overlap: na+in
            OR (p_datum_van <= mpr.datum_van AND p_datum_tot >= mpr.datum_tot) -- overlap:omsluitend
            )
        INTO aantal;

        -- The total amount of materials
        SELECT m.aantal_beschikbaar FROM materialen m
        WHERE m.id = p_mat_id
        INTO tot;
        -- The test variable is holding the amount of materials that's still available
        SELECT tot-aantal INTO test;
        -- Checking if im not ordering more then there is available
        IF p_nodig < test THEN
            -- Checking if this material is already hired from this reservation id
            SELECT mpra.id, mpra.aantal FROM materialen_per_reservatie mpra
            WHERE (mpra.reservaties_id = p_res_id
            AND   mpra.materialen_id = p_mat_id) INTO upda, voriga;
            -- if voriga is bigger then zero it means that there is already an reservatie for this material for this reservation so im not inserting but updating
            IF voriga > 0 THEN
                -- Selecting the previous amount and add it with the p_nodig amount
                SELECT voriga+p_nodig INTO nieuwa;
                UPDATE materialen_per_reservatie SET materialen_per_reservatie.aantal = nieuwa WHERE reservaties_id = p_res_id AND materialen_id = p_mat_id;
            ELSE
                -- There is no reservation for this material with this reservation id so i my insert a new row
                INSERT INTO materialen_per_reservatie(reservaties_id, materialen_id, aantal, effectief_gebruikt, opmerking, datum_van, datum_tot) VALUES (p_res_id, p_mat_id, p_nodig, p_nodig, p_mat_opmerking, p_datum_van, p_datum_tot);
            END IF;
        END IF;
END$$

我测试了INSERT/UPDATE查询的独立性,它们都正常工作。

日期值周围的引号在哪里

试试这个:

call aantal_besch_mat_van_tot('2007-03-13', '2007-03-14', 15, 6, 50, 'Im hiring this material');

注:日期类似于“2007-03-13”,而不是2007-03-13,2007-03-13实际上是数字1991 ie 2007-3-13=1991

隔离级别是多少?你试过把它放在交易中吗?对不起,那是个打字错误。我已经在用这个日期了对不起,这是个打字错误。我已经在mysql中使用了上面提到的那个
call aantal_besch_mat_van_tot('2007-03-13', '2007-03-14', 15, 6, 50, 'Im hiring this material');